After orientation change buttons on a widget are not responding

I have two buttons on a widget that change some items in a widget, if an orientation is changed on a phone, buttons do nothing. I read http://developer.android.com/guide/topics/resources/runtime-changes.html but this is all about activity not widget.

    @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) 
{
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);

    Intent active = new Intent(context, TvWidget.class);
    active.setAction(ACTION_WIDGET_RECEIVER);
    mDbHelper = new DbAdapter(context);
    fillChannelList(context, appWidgetIds[appWidgetIds.length-1]);
    Set keys = channelsImages.keySet();
    Iterator iter = keys.iterator();
    while(iter.hasNext())  
    {
        if(channelId == 0) 
        {
            channelId = iter.next();
            break;
        }
    }
    SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
    Editor edit = settings.edit();
    edit.putInt("channelId", channelId);
    edit.putInt("appWidgetIds", appWidgetIds[appWidgetIds.length-1]);
    edit.commit();
    active.putExtra("net.aerosoftware.tvvodic.appWidgetIds", appWidgetIds);
    PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
    remoteViews.setOnClickPendingIntent(R.id.button_next, actionPendingIntent);

    Intent refresh = new Intent(context, TvWidget.class);
    refresh.setAction(ACTION_WIDGET_REFRESH);
    refresh.putExtra("net.aerosoftware.tvvodic.appWidgetIds", appWidgetIds);
    PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refresh, 0);
    remoteViews.setOnClickPendingIntent(R.id.button_refresh, refreshPendingIntent);

    updateView(context);
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}

11
задан Vadim Kotov 21 August 2017 в 11:25
поделиться