Question

I am writing a launcher activity to host appwidgets. Basically here is what I am doing.

  1. My container view for all appwidgets is some customized ViewGroup.
  2. When adding widgets, I do call config activity first for the widget being added.
  3. I am calling AppWidgetHost.startListening() in main activity.onStart() and stopListening() in onStop()
  4. When adding widget, here is what I do application.getAppWidgetManager().bindAppWidgetIdIfAllowed(appWidgetId, componentName); AppWidgetHostView hostView = application.getAppWidgetHost().createView(context, appWidgetId, appWidgetInfo); hostView.setAppWidget(widgetId, appWidgetInfo); myViewGroup.addView(hostView);
  5. I am not seeing RemoteException in logs and calling AppWidgetHost.startListening() aggressively doesn't help.

In addition, not all widgets fail to update, the stock clock widget, for example, works fine. This happens especially on Minimalistic Text Widget and some others. Once the widget has been added, it is able to update for 1~2 minutes before stop working. The other related observation is that when I tap the Minimalistic widget, modify the layout and save. The new layout won't be applied to the existing widget. That makes me feel there is something buggy in my code, but I cannot figure out where.

Thanks for help in advance!

Sorry I cannot paste detail code here because they are scattered around. But I can provide any detail information if you need. Thanks again!

Was it helpful?

Solution

Never mind. I figured out eventually. The reason is that I was using application context instead of activity context when creating AppWidgetManager and AppWidgetHost.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top