Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:47:06+00:00 2026-05-23T15:47:06+00:00

i am using this tutorial to create a widget. My problem is with the

  • 0

i am using this tutorial to create a widget. My problem is with the buttons. In my widget there are three lines, each consists of a textview and three buttons. With the code below when user clicks on ButtonP1, ButtonP2 or ButtonP3 a toast msg should be seen with different messages. The problem is that no matter which button i click, i get the first toast msg every time (“Message for Button P1”).

  public class HelloWidget extends AppWidgetProvider {

    public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget";
    public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";

        @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        context.startService(new Intent(context, UpdateService.class));
            Intent intent = new Intent(context, UpdateService.class); 
        context.startService(intent);

         RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widgetmain);

         Intent active = new Intent(context, HelloWidget.class);
         active.setAction(ACTION_WIDGET_RECEIVER);
         active.putExtra("msg", "Message for Button P1");

         PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
         remoteViews.setOnClickPendingIntent(R.id.ButtonP1, actionPendingIntent);

         Intent active2 = new Intent(context, HelloWidget.class);
         active2.setAction(ACTION_WIDGET_RECEIVER);
         active2.putExtra("msg", "Message for Button P2");

         PendingIntent actionPendingIntent2 = PendingIntent.getBroadcast(context, 0, active2, 0);
         remoteViews.setOnClickPendingIntent(R.id.ButtonP2, actionPendingIntent2);

         Intent active3 = new Intent(context, HelloWidget.class);
         active3.setAction(ACTION_WIDGET_RECEIVER);
         active3.putExtra("msg", "Message for Button P3");

         PendingIntent actionPendingIntent3 = PendingIntent.getBroadcast(context, 0, active3, 0);
         remoteViews.setOnClickPendingIntent(R.id.ButtonP3, actionPendingIntent3);

         appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);

   }

    @Override
    public void onReceive(Context context, Intent intent) {

        final String action = intent.getAction();
        if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
        final int appWidgetId = intent.getExtras().getInt(
        AppWidgetManager.EXTRA_APPWIDGET_ID,
        AppWidgetManager.INVALID_APPWIDGET_ID);
        if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
        this.onDeleted(context, new int[] { appWidgetId });
        }
        } else {
          // check, if our Action was called
          if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
        String msg = "null";
        try {
        msg = intent.getStringExtra("msg");
        } catch (NullPointerException e) {
        Log.e("Error", "msg = null");
        }
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
     }
          super.onReceive(context, intent);
         }

    }


}

I don’t think the .xml file for the layout is necessary so i am not wasting space with it.

What am i missing?

Solution

Intent configIntent4 = new Intent(context, Call1.class);
         configIntent4.setAction(ACTION_WIDGET_CONFIGURE);
         PendingIntent configPendingIntent4 = PendingIntent.getActivity(context, REQUEST_CODE_FOUR, configIntent4, 0);
         remoteViews.setOnClickPendingIntent(R.id.Button01, configPendingIntent4);


         Intent configIntent5 = new Intent(context, Call2.class);
         configIntent5.setAction(ACTION_WIDGET_CONFIGURE);
         PendingIntent configPendingIntent5 = PendingIntent.getActivity(context, REQUEST_CODE_FIVE, configIntent5, 0);
         remoteViews.setOnClickPendingIntent(R.id.Button02, configPendingIntent5);


         Intent configIntent6 = new Intent(context, Call3.class);
         configIntent6.setAction(ACTION_WIDGET_CONFIGURE);
         PendingIntent configPendingIntent6 = PendingIntent.getActivity(context, REQUEST_CODE_SIX, configIntent6, 0);
         remoteViews.setOnClickPendingIntent(R.id.Button023 configPendingIntent6);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:47:06+00:00Added an answer on May 23, 2026 at 3:47 pm

    PendingIntent.getBroadcast(context, 0, active, 0)
    Parameters:
    context The Context in which this PendingIntent should perform the broadcast.
    requestCode Private request code for the sender (currently not used).
    intent The Intent to be broadcast.
    flags

    You should use different requestCode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this tutorial to create a login form http://www.ryancoughlin.com/2008/11/04/use-jquery-to-submit-form/ It authenticates against
I have been using Entity Framework CTP with Code-First as in this tutorial by
I've been using this tutorial to create a game loop. In the section marked
I'm trying to create a game loop using this tutorial . I have tried
I built a Jquery dropdown menu using this tutorial . It works across browsers
I just installed Glassfish on my Ubuntu server (No GUI) using THIS tutorial. Everything
I'm trying to get Django running on GAE using this tutorial . When I
I followed this tutorial: https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf However, I can't seem to set the path right.
I'm following the Railscasts tutorial on using OpenID with AuthLogic . This command: $
Using this question as the base is there an alogrithm or coding example to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.