Widget does not appear after rebooting the phone

I created a widget that works fine until I restart the phone, then the widget does not render it invisible, but if I hold and click, I can throw it in the trash

I have a function 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, which did nothing, because nothing was updated, but thinking that it would be called after the phone rebooted, I copied the code that I had in the function

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

but this doesn’t seem to be very much .... suggestions?

+3
source share
1 answer

When the phone restarts, it will call onEnable instead of onUpdate.

- -

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

, YourAppWigetProvider. this

+11

Source: https://habr.com/ru/post/1771230/


All Articles