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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:01:45+00:00 2026-06-15T16:01:45+00:00

I have been working with this problem for three days now and I’ve looked

  • 0

I have been working with this problem for three days now and I’ve looked at every single question on here for an answer. I have a widget with a button on it and all I would like it to do is start a service everytime it is clicked. The problem is that the button stops working randomly. I can’t recreate it at all and I have no idea what causes it. My service calls stopSelf(); but I have had this problem with a broadcast receiver also so I believe the problem to be in the widget and not in the service. Here is the code

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

Log.i("Widget", "onUpdate");

final int N = appWidgetIds.length;

    for (int i=0; i<N; i++) 
    {

        int appWidgetId = appWidgetIds[i];

        Log.i("Widget", "onUpdateLoop");


        Intent intent = new Intent(context, ServiceWidgetAction.class);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        PendingIntent pendingIntent = PendingIntent
                .getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        RemoteViews views = new RemoteViews(context.getPackageName(), 
               R.layout.widget);

        views.setOnClickPendingIntent(R.id.widgetButton, pendingIntent);

        views.setTextViewText(
                R.id.widgetTextView,
                "Some text");

        appWidgetManager.updateAppWidget(appWidgetId, views);

    }

}

I’ve checked this code over and over and I have no idea why it is doing this. It does this on 3 separate phones and I can’t recreate it. I’ve tried force stopping the app, clearing it from a task manager adding new widgets etc. to get the widget to stop working and it won’t. However when I woke up this morning the widget no longer works. Any help would be GREATLY appreciated.

  • 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-15T16:01:46+00:00Added an answer on June 15, 2026 at 4:01 pm

    I ended up figuring out the problem. I was updating the widget from other places in the app and I did not have the complete code for each one. In other words my app updated the textviews in the widget like this

        RemoteViews views = new RemoteViews(context.getPackageName(), 
               R.layout.widget);
    
        views.setTextViewText(
                R.id.widgetTextView,
                "Some text");
    
        appWidgetManager.updateAppWidget(appWidgetId, views);
    

    But it needed the entire code to keep the button registered like this:

        Intent intent = new Intent(context, ServiceWidgetAction.class);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
        PendingIntent pendingIntent = PendingIntent
                .getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    
        RemoteViews views = new RemoteViews(context.getPackageName(), 
               R.layout.widget);
    
        views.setOnClickPendingIntent(R.id.widgetButton, pendingIntent);
    
        views.setTextViewText(
                R.id.widgetTextView,
                "Some text");
    
        appWidgetManager.updateAppWidget(appWidgetId, views);
    

    So bottom line is whenever you update a widget from within your app, make sure it looks exactly like the code in the widget itself. Don’t leave anything out.

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

Sidebar

Related Questions

I have been working on this problem for 2 days now and it's an
I have been working on this problem for close to 4 days now. I
I have been working on this problem for a while now. I am trying
Morning, I have been working on this problem for a few days and cannot
Hi For many days I have been working on this problem in MySQL, however
I've been working on this problem for a few hours and have used many
I have been working on the following problem from this book . A certain
Have been working on this question for a couple hours and have come close
I have been working on this for days but I don't get it so
Okay guys I have a database I have been working on for days now.

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.