Android Widget: How to determine which button was clicked?

advertisements

My widget has several ImageButtons, to set onClicked event for them, I use PendingIntent:

Intent intent = new Intent(context, UpdateService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
remoteViews.setOnClickPendingIntent(R.id.Button1, pendingIntent);

If I want to use only one PendingIntent and Service for all Buttons, how do i determine which button was clickd? Thanks you!


I don't understand why you want to only use one PendingIntent. The answer is to create multiple intents for each click. The simplest is to give each Intent a special action. This way you can tell the click events apart when you receive the intent.