Widget Not showing up after phone restart

蓝咒 提交于 2019-12-10 20:10:58

问题


I created a widget that works great until I restart the phone, then the widget doesn't display it is invisible but if i hold and click i can throw it in the garbage

I have a function that is called from my configure activity in my widgetprovider that does the following:

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
            int appWidgetId, int version) 
 {
        if(savedType == -1)
            savedType = version;
//   android.os.Debug.waitForDebugger();
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);

    Intent configIntent = new Intent(context, Configure.class);
    configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);


    Uri data = Uri.withAppendedPath(
            Uri.parse(appWidgetId + "://widget/id/")
            ,String.valueOf(appWidgetId));
    configIntent.setData(data);




    PendingIntent pendingIntent = PendingIntent.getActivity
    (context, 0, configIntent,
    PendingIntent.FLAG_UPDATE_CURRENT);

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

    views.setImageViewResource(R.id.MainImage, lv_images[version]);

    appWidgetManager.updateAppWidget(appWidgetId, views);
}

I had my onUpdate not doing anything because there is never anything to update but thinking this would be called after a phone restart i copied the code i had in the function

for(int i = 0; i < appWidgetIds.length; ++i)
{
     updateAppWidget(context, appWidgetManager, appWidgetIds[i], savedType);
}

but this didn't seem to do much either.... suggestions?


回答1:


When phone restart, it will call onEnable instead of onUpdate.

--update--

int[] allids = AppWidgetManager
    .getInstance(Context)
    .getAppWidgetIds(new ComponentName(Context, YourAppWidgetProvider.class);

This will get all ids that is under the control of YourAppWigetProvider. Read more on this



来源:https://stackoverflow.com/questions/4011605/widget-not-showing-up-after-phone-restart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!