Yalantis: iOS, Android And Web App Development Company

The Dark Side of Android App Widgets

Widgets are among destinctive features of Android OS, and one of the reasons you should convert iPhone app to Android. We already wrote how to build widgets on Android and why to build them, in the first place. This time, however, we decided to tell you why you shouldn't. We identified the most disturbing problems with Android app widgets which can spoil user experience. One of them is when widgets freeze, and the other is when widgets don't show up in the widgets list.

Let's see what the root cause of these issues is, and what we can do about it.

I. When widgets freeze

As you know, we have an app. It's called My Day and it helps you keep track of the most important days in your life. To make user experience better, we developed a widget that's basically, a countdown timer which displays days, minutes, seconds, or any other time unit that a user chooses.

Read alsoThe cost for IT services in the world

The content of our widget is often renewed which makes the widget prone to freezing. The same problem can be detected in widgets that display clock, graphs, weather, and other content that gets updated frequently. The only way to defrost a widget is to reboot a phone or restart a launcher.

I found the following bug after conducting searches in Android bug tracker:

Widgets occasionally freeze entirely 

Reported Apr 2, 2012. Status: New

Widgets are "frozen" visually/graphically (no longer update). That is, if the widget involves content/drawables that updates or changes (like a clock, weather widget, or even the stock Power Control toggle widget) you will notice that it no longer changes. The graphics are stuck in one state and will not change. So if you use the stock Power Control Toggle widget (the one with wifi, bluetooth, brightness control, etc.) and try to toggle some functions, you'll notice that the drawables will not change.

After reading all 154 comments, I came to the following conclusions:

  • The bug is detected on Android OS 4.0.3-4.2.2 (inclusively), regardless of a launcher type.
  • Android OS 4.4.4 and 5.0 were mentioned only once, which means it's not a common problem on the latest versions of Android.
  • The reproduction of the bug is unstable in all widgets. Even a standard Power Widget is not immune to this issue.

The cause of the problem

To interact with AppWidget service almost all home apps use AppWidgetHost, which you’re well aware of. When you create an AppWidgetHost instance for your app, you’ll get a CallBack to connect with AppWidgetService.

While updating widgets, AppWidgetService can sometimes receive RemoteException error which results in a reference to a CallBack being removed. If you get "host.callbacks = null," it means your widget cannot be updated. The only way out is to restart the launcher, because a CallBack gets assigned after AppWidgetHost calls a method startListening(), which can only happen in the method onCreate(on) in the Launcher class.

This story is described in the comment #56. Here is an example of code the author of the comment used to illustrate the widget freezing problem. This code was taken from Android OS:

void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views, boolean isPartialUpdate) {
 // allow for stale appWidgetIds and other badness
 // lookup also checks that the calling process can access the appWidgetId
 // drop unbound appWidgetIds (shouldn't be possible under normal circumstances)
 if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) {

 // We do not want to save this RemoteViews
 if (!isPartialUpdate) id.views = views;

 // is anyone listening?
 if (id.host.callbacks != null) {
 try {
 // the lock is held, but this is a oneway call
 id.host.callbacks.updateAppWidget(id.appWidgetId, views);
 } catch (RemoteException e) {
 // It failed; remove the callback. No need to prune because
 // we know that this host is still referenced by this instance.
 id.host.callbacks = null;

The solution

The same person who wrote the comment mentioned above found a solution to the problem. He created a system image and simply fixed the issue in the source code. The bug disappeared as if it has never been there. The only thing is that it disappeared on his personal device only. The rest of the world that uses Android has to bear with the widget freezing problem, unless they know how to properly reflash the system.  

Otherwise, you can restart a launcher and it will temporarily fix the problem. This is not the perfect solution, but, at least, it doesn’t require coding skills.

What conclusions can we come to?

  1. The root of all evil is incorrect functioning of the launcher.
  2. There is no fully-fledged solution to the problem.

But we didn't give up and investigated the issue further.

Alternative solution

It turns out that the widget freezing bug is not only detected when a launcher fails, but also when time on a device is changed by a user. It's enough to go a day back in time, and a widget won't update.

My suspicion fell on the service that sends updates to the widget. TimerTask, which this service has under the hood, is the cause of the problem. I found an interesting question on StackoverFlow, which illustrates a similar problem -- TimerTask stops working after the time is changed. This only confirmed my assumption.

When we substituted TimerTask with Handler... Bingo! Our widget ceased freezing!

This solution didn't fix the above-mentioned OS bug, but the widget freezing scenarios became rare and short-lived. Nevertheless, system bugs still remain unfixed. Shame on Google!

Read also: How we developed FlipViewPager animation on Android

II. A widget doesn't show up in the widgets lists

When widgets don't show up in the widget listIf you ever dealt with widgets, you probably know that if you don't launch Activity after installing an app, the widget may not appear in the widget list, and if it doesn’t, you won’t be able to add it to the Home screen right away.

When we tested this issue on our app My Day a month ago the widget didn’t show up in the widget list, but when we tried doing that again an hour ago, it actually did show up. To that I can only add that widgets are rather unpredictable per se.

After I tested widgets on different devices, I discovered that the problem with the widget lists, is, in fact, more serious than it seems. Even if you do launch Activity, a widget won't always go where it belongs.

There are two ways to solve this problem.

Solution 1

I did a little research and found the bug “Widget does not appear after installation” -- a pretty similar problem to the one we had with the My Day app widget.

The author suggests to reboot the device to solve this issue. As sad as it sounds, what we’ve got here is another Android OS problem.

Solution 2

I googled a little more, and found that Android 4.0+ users complain about widgets not appearing in their widget lists too.

I also came across the following post on Stackoverflow: “The only way I found to work around it in ICS (Ice-Cream Sandwich or Android 4+) is to go to settings > apps > Launcher and "stop" it.

I checked that out, and it worked! A widget will show up after stopping the launcher, and there is no need to reboot the device.

The cause of the problemAndroid widget problems

Since restarting a launcher helped us solve the problem, it means that the launcher is again the cause of the problem.

More than that, I found out that if you delete an app, its widget lingers in the list until you reboot the device. I tested this issue on my Nexus 5 Android 5.0.1 with Beautiful Widgets Free app to prove the point.

Unfortunately, I didn't find the way to fix the bug, but here is a piece of advice for you: if your app has a widget, you should force your users to launch Activity first.

This won’t always solve the problem, but it seems there is nothing we can do about it.

I hope Google pays attention to the bugs in their Android system to make everybody happy and the world a better place.


Apps for smartwatches

A watch face constructor for Android Wear and the Apple Watch extension for the My Day app are two examples of products that we built for wearables

How We Created Animated My Day Watch App Inspired by Apple’s Activity App
Written by Anna Gerasymenko and Ivan Nesterenko

How We Created Animated My Day Watch App Inspired by Apple’s Activity App

Have you already jumped on the Apple Watch bandwagon? We just did and are only too excited to share our...

Customizable Constructor for Designers of Android Wear
Written by Andriy Hristyan

Customizable Constructor for Designers of Android Wear

Gone are the days when watches were devices to check out the time. Now people use smart watches for doi...

Audio processing on Android

Technology behind Horizon, our open source library for sound visualization

Drawing a Cubic Bezier with OpenGL ES for Sound Visualization on Android
Written by Artem Kholodnyi

Drawing a Cubic Bezier with OpenGL ES for Sound Visualization on Android

Our experience drawing Bezier curves with Android Canvas for Horizon, our open source library for sound visualization.

How to Process Audio for Your Android project
Written by Roman Kozlov

How to Process Audio for Your Android project

Sound manipulation techniques that we used for our Horizon open source library for sound visualization.

Introducing Horizon, Our Own Open Source Library for Sound Visualization
Written by Roman Kozlov

Introducing Horizon, Our Own Open Source Library for Sound Visualization

Horizon is an Android library that visualizes sound quickly and beautifully

See what else we can do

Check out our knowledge and capabilities

Let's talk code