1

I use the following:

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

        Intent configIntent = new Intent(context, ConfigureActivity.class);
        configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        configIntent.setAction(ACTION_UPDATE);

        PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.config_button, configPendingIntent);

        Intent smsIntent = new Intent(context, TurboSMSWidget.class);
        smsIntent.putExtra(APP_ID, appWidgetId);
        smsIntent.setAction(ACTION_SEND);

        PendingIntent smsPendingIntent = PendingIntent.getBroadcast(context, 0, smsIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.send_button, smsPendingIntent);

        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
}

The widget creation works great, but every time i run a new widget the old one is disabled. I can't use buttons anymore, it is like frozen on the home screen. What's wrong with this code?

Lorenzo Sciuto
  • 1,655
  • 3
  • 27
  • 57

1 Answers1

1

I think the problem is in PendingIntent. The new instance of PendingIntent overwrite the old one. You should use unique Intent for inialization of PendingIntent. Here is the discussions that may help you: Multiple Instances Of Widget Only Updating Last widget, How can I correctly pass unique extras to a pending intent?, android pending intent notification problem

Community
  • 1
  • 1
Yury
  • 20,618
  • 7
  • 58
  • 86