Android AppWidget does not show up in the menu in honeycomb until reboot

前端 未结 4 817
轻奢々
轻奢々 2020-12-30 12:53

I have created an AppWidget for Honeycomb which is working well, except that when first installed, it does not show up in the Widgets menu so it can not be added to a home s

4条回答
  •  情深已故
    2020-12-30 13:15

    To solve this problem with my widget I send widget update broadcast, like this in my WidgetController.class:

    Intent intent = new Intent();
    intent.setClassName(context, context.getPackageName() + ".WidgetProvider");
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,
            getWidgetIds(context));
    context.sendBroadcast(intent);
    

    then to provide stable widget initialization in the system I send this broadcast from Application object when application or widget start:

    public class MyApp extends Application {
    
        @Override
        public void onCreate() {
    
            WidgetController.getInstance().updateWidget(getApplicationContext());
        }
    }
    

    !!! Important: when AppWidget hosts in application it's enough, but when AppWidget separated from it you should use way proposed by @John above in this topic.

提交回复
热议问题