Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some 3rd party widgets stop updating after application upgrade

My application hosts user installed widgets, same as a launcher application.

Once I bind the widget, everything works fine. Widgets are created, updated automatically, I can click to navigate inner views.

Everything keeps working fine, until I update my application from Play store (or manually with a signed APK).

After the update, the widgets still show but they won't update anymore. Some widgets function when I click on them but the view is stuck and never gets updated until I re-create the widget (get a new ID and bind it).

I tried forcing an update using

Intent intent = new Intent();
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.setComponent(appWidgetInfo.provider);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]
                {appWidgetId});
context.sendBroadcast(intent);

but that doesn't help...

I wanted to try a forced update on click but I couldn't find any way to get the widget's RemoteViews (as this is not my widget, I just host it).

RemoteViews views = 
      new RemoteViews(context.getPackageName(),R.layout.mywidget_layout);

Intent updateIntent = new Intent();
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
updateIntent.putExtra(myWidgetProvider.WIDGET_IDS_KEY, ids);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
      context, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT);

views.setOnClickPendingIntent(R.id.view_container, pendingIntent);

Also implemented an AppWidgetProvider to listen to widgets' ID changes (APPWIDGET_HOST_RESTORED) but it doesn't get called on my application update.

My next step would be to re-create all widgets after application update, but I really prefer not to do so.

Would appreciate any help!

like image 386
Lior Iluz Avatar asked May 18 '15 11:05

Lior Iluz


People also ask

How do I force a widget to update?

Any call to updateWidgets() will cause all instances of our widget to be updated. Of course, be careful not to update to often - widget updates use battery power. Bear in mind that the broadcast is received by ALL widget providers, and its our special keys that ensure it is only our widgets that actually update.


1 Answers

Solved.

The last thing I wanted to do, was probably the first thing I should have tried. I moved on to re-creating the widgets and I found that I don't have to fully re-create them, just re-call bindAppWidgetIdIfAllowed() with the same Widget ID I already have.

The method will return true if everything is still OK and if not, the widget may not be installed anymore or you need to trigger its configuration screen.

like image 158
Lior Iluz Avatar answered Sep 21 '22 20:09

Lior Iluz