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 8383781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:15:00+00:00 2026-06-09T17:15:00+00:00

I have a widget that mostly does what I want it to (Starts an

  • 0

I have a widget that mostly does what I want it to (Starts an intent) but I’m wondering how I can squeeze multiple intents into one widget provider.

I have tried all the usual means of getting this done:

  • Using more then one intent
  • using a second widget with the same theme settings
    and a few others here and there that were ultimately failures.

Generic code:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {

        Intent startIntent = new Intent(context, myClass.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, startIntent, 0);

        // Get the layout for the App Widget and attach an on-click listener to the button
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.MyWidget);
        views.setOnClickPendingIntent(R.id.startBtn, pendingIntent);

        // Tell the AppWidgetManager to perform an update on the current App Widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }       
}

So I’m trying to figure out how to get more then one button on the widget. Since its set up for three and I know one of them works so I’m 1/3 the way there.

here is the XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/startBtn"
    android:layout_width="150dp"
    android:layout_height="75dp"
    android:layout_marginBottom="5dp"
    android:background="@drawable/mybg"
    android:gravity="center"
    android:text="First Menu Item"
     />

<TextView
    android:id="@+id/startBtn2"
    android:layout_width="150dp"
    android:layout_height="75dp"
    android:layout_marginBottom="5dp"
    android:background="@drawable/mybg"
    android:gravity="center"
    android:text="Second menu item" />

<TextView
    android:id="@+id/startBtn3"
    android:layout_width="150dp"
    android:layout_height="75dp"
    android:layout_marginBottom="5dp"
    android:background="@drawable/mybg"
    android:gravity="center"
    android:text="Third menu item" />

</LinearLayout>
  • 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-06-09T17:15:02+00:00Added an answer on June 9, 2026 at 5:15 pm

    OK, so you almost got it! The idea is to create 3 different PendingIntents and 3 different Intents, and then call setOnClickPendingIntent 3 times. One for each action and button. Here is an example, assuming the three activities are myClass, myClass2, and myClass3. With the below code, each button will fire off a different intent.

    for (int appWidgetId : appWidgetIds) {
    
        Intent startIntent = new Intent(context, myClass.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, startIntent, 0);
    
        Intent startIntent2 = new Intent(context, myClass2.class);
        PendingIntent pendingIntent2 = PendingIntent.getActivity(context, 0, startIntent2, 0);
    
        Intent startIntent3 = new Intent(context, myClass3.class);
        PendingIntent pendingIntent3 = PendingIntent.getActivity(context, 0, startIntent3, 0);
    
        // Get the layout for the App Widget and attach an on-click listener to the button
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.MyWidget);
        views.setOnClickPendingIntent(R.id.startBtn, pendingIntent);
        views.setOnClickPendingIntent(R.id.startBtn2, pendingIntent2);
        views.setOnClickPendingIntent(R.id.startBtn3, pendingIntent3);
    
    
        // Tell the AppWidgetManager to perform an update on the current App Widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a widget that, when pressed, sends a broadcast that starts a CountDownTimer
I have a home-screen widget that has an icon that starts/so pose to bring
I have searched up and down the internet for a jQuery widget that does
I have this widget that toggles sound on off but instead of that I
I have a widget that contains an iframe. The user can configure the url
I have a button widget that I had a successful rotation animation on but
I have a javascript widget that can be inserted on an a plain-old html
I have a widget that gets updated when I press it, but I would
I have Android widget that contains two buttons. But i have no idea how
I have a widget that launches an activity, but when the activity finishes using

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.