Android - widget breaks after reboot / reset

I created the widget "Android Home Screen", which displays text and has 2 clicks, which I work during normal operation, no problem. This is until HTC sense / launcher decides to restart, which does most days. After a reboot, one of the click listeners stops working and can force the widget to force close.

onClickListener 1 = starts the action and passes some text strings to it

onClickListener 2 = Triggers FORCE_WIDGET_UPDATE

After restarting the launcher, activity still stops, but updating the widget does not work.

Here is the gist of the update code.

public static String updateString = "org.software.appname.FORCE_WIDGET_UPDATE";
public void onReceive(Context ctx, Intent intent){
        showIntent=intent.getAction();
        Log.d(TAG, showIntent);
        if (updateString.equals(intent.getAction())){

            Log.d(TAG, "onReceive, Force");
        AppName.updateViews = new RemoteViews( ctx.getPackageName(),R.layout.main );

            <Code to update text, update widget view and load new intents>

        ComponentName me = new ComponentName( ctx, AppName.class );
            AppWidgetManager.getInstance( ctx ).updateAppWidget( me, updateViews );

        } else super.onReceive(ctx, intent);

onRecieve if, , .

logcat, , , , . , .

!: -)

: , appWidgetIds [] , onUpdate onReceive, , , . logcat, , , , , onUpdate.

public void onReceive(Context ctx, Intent intent){
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(ctx);
        int[] appWidgetIds = intent.getIntArrayExtra("appWidgetIds");
        onUpdate(ctx, appWidgetManager, appWidgetIds);
        Log.d(TAG, "onReceive log");
}
+3

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


All Articles