سؤال

I have an app widget which contains 4 buttons and logic of these buttons (what they should do when they are clicked) are different. I have used the following pattern for assigning PendingIntents to them

/* for button 1 */
pendingIntent = PendingIntent.getService(context, 1000 + widgetId,
    intent, PendingIntent.FLAG_UPDATE_CURRENT);

/* for button 2 */
pendingIntent = PendingIntent.getService(context, 2000 + widgetId,
    intent, PendingIntent.FLAG_UPDATE_CURRENT);

/* for button 3 */
pendingIntent = PendingIntent.getService(context, 3000 + widgetId,
    intent, PendingIntent.FLAG_UPDATE_CURRENT);

/* for button 4 */
pendingIntent = PendingIntent.getService(context, 4000 + widgetId,
    intent, PendingIntent.FLAG_UPDATE_CURRENT);

And this code works fine. But I think this is not a good practice. I also tried using Fill-in Template mechanism but it wont work.

Can any one please tell me what is the best practice for assigning multiple different intents to multiple buttons on a single widget?

Thanks

هل كانت مفيدة؟

المحلول

I think my answer (here) to another question can help you. If you need more information or something is not clear don't hesitate and ask.

Here is only a part of mentioned answer:

// set action
buttonOneIntent.setAction(BUTTON_ONE_CLICKED);
buttonTwoIntent.setAction(BUTTON_TWO_CLICKED);
buttonThreeIntent.setAction(BUTTON_THREE_CLICKED);
buttonFourIntent.setAction(BUTTON_FOUR_CLICKED);
// ......
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top