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

  • Home
  • SEARCH
  • 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 8835159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:11:46+00:00 2026-06-14T09:11:46+00:00

My widget is comprised of 2 buttons and a listview displaying data. Most times,

  • 0

My widget is comprised of 2 buttons and a listview displaying data. Most times, when the widget provider’s onUpdate method is called, everything loads normally and everyone is happy.

However I’ve noticed sometimes after the update method is called, the widget just completely fails to load its data. The listview is empty, and all of the buttons are non-responsive. It’s as if I initialized the layout into the widget, but none of the pending intents nor the adapter for list were set.

I logged everything and found that this isn’t the case. The pending intents ARE created, as is the list adapter, every time, including the random time when it fails. For a long time I thought it had to do with how the list data is populated into the adapter, but seeing it work every single time, coupled with the fact that the button intents don’t work as well leads me to believe the method updateAppWidget(ComponentName, RemoteViews) is what is failing. However, there are no error stacks to help me confirm this.

Here is the code which runs in a separate service called by the AppWidgetProvider’s onUpdate method:

@SuppressWarnings("deprecation")
private void updateWidget(int[] ids) {

    AppWidgetManager widgetManager = AppWidgetManager.getInstance(this);
    int[] widgetIds = widgetManager.getAppWidgetIds(new ComponentName(this, WidgetReceiver.class));

    for (int currentWidgetId : widgetIds) {

        RemoteViews widget = new RemoteViews(this.getPackageName(), R.layout.widget_layout);

        Intent intent = new Intent(this, WidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, currentWidgetId);
        intent.putExtra("random", randomNumber);
        randomNumber++;
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

        widget.setRemoteAdapter(currentWidgetId, android.R.id.list, intent);

        Intent clickIntent = new Intent(this, DetailsActivity.class);
        PendingIntent pending = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        widget.setPendingIntentTemplate(android.R.id.list, pending);

        Intent settingsIntent = new Intent(this, WidgetSettingsActivity.class);
        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent settingsPending = PendingIntent.getActivity(this, 0, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        widget.setOnClickPendingIntent(R.id.widget_settings, settingsPending);

        Intent mainIntent = new Intent(this, MainActivity.class);
        PendingIntent mainPending = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        widget.setOnClickPendingIntent(R.id.widget_logo, mainPending);

        ComponentName widgetCompName = new ComponentName(this, WidgetReceiver.class);
        widgetManager.updateAppWidget(widgetCompName, widget);
    }
}

What is most frustrating about this bug is that I can’t reliably recreate it. Sometimes I get (un)lucky and it shows it ugly head, other times (the majority of the time) it works perfectly.

Another thing that I thought was interesting is that I’ve seen the same exact problem in Facebook’s widget. Due to NDA I can’t show a screen of my app when it fails, but I can show a screen of Facebook’s identical problem:

Facebook fail

When Facebook’s widget looks like this, it has the exact same issues as mine. No data loaded, all buttons are unresponsive.

For both Facebook and my widget, a subsequent update interval will usually make the problem go away.

As much as I appreciate that I’m not the only one who is running into this, I still don’t want to release until I fix this. Has anyone here run into this, and better yet found a solution, or even a cause of the problem? Thanks for helping.

EDIT: Something interesting. I ran an experiment where I set the update interval to a full day rather than every 30 minutes. My hypothesis was that maybe the update method wasn’t the cause, it was something else which was causing the widget to become blank and unresponsive.

Sure enough, after about 2 hours, I checked my phone and the widget was dead, despite no update method being called. This would lead me to believe that something else is causing this problem, NOT widgetManager.updateAppWidget(widgetCompName, widget); like I previously thought.

I know that a configuration change can cause the widget to be rebuilt, and thus it is possible that it can fail. However, I already use the Service class’s onConfigurationChanged method to reload the widget if necessary. Is there another case like configuration change which can cause the widget to destroy and recreate itself?

  • 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-14T09:11:47+00:00Added an answer on June 14, 2026 at 9:11 am

    After a lot of blood, sweat, and tears I found the solution. I am going to hold off on confirming this answer for a few days to make sure that the error doesn’t pop back up, but after a lot of observation I think it is resolved.

    So I was right in my edited comments in the original question. It wasn’t the update method of the AppWidgetManager that caused the problem, but rather some other Android process which caused the app widget to recreate itself. Unfortunately I couldn’t isolate that trigger, but I did find a solution.

    In my RemoteViewsFactory class (basically the wrapper which is used to load the data set), I had a block of code that looked like this:

    RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.widget_layout);
    if(mItems.size() == 0)
        views.setViewVisibility(R.id.widget_empty, View.VISIBLE);
    else
        views.setViewVisibility(R.id.widget_empty, View.GONE);
    
    AppWidgetManager manager = AppWidgetManager.getInstance(mContext);
    ComponentName widgetCompName = new ComponentName(mContext, WidgetReceiver.class);
    manager.updateAppWidget(widgetCompName, views);
    

    Basically, if the list was empty, I showed a Loading message that took up the entire area where the listview is located. If the list wasn’t empty, I’d just hide that message.

    So this is what was happening: When the factory was destroyed (presumably for memory purposes) the widget itself was not. So all of the code which sets the intents for the data and stuff was not run. However, the factory was recreated, which ran that block of code which updated the app widget with the new remote views object. This remote views object didn’t do any of the methods that you see in my onUpdate() method I originally posted, so all of its features didn’t work.

    Moral of the story: DON’T use updateAppWidget in your RemoteViewsFactory class! Now it may work if you run all the necessary lines, but I can’t confirm that.

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

Sidebar

Related Questions

I have created a widget for my app. Everything works fine, but the only
class Widget; std::vector< std::shared_ptr<Widget> > container class Criterium { public: bool operator()(const Widget& left,
jQuery.widget(ui.test, { _init: function(){ alert(this.element.innerHTML); } }); How do I make it so when
class Widget { public: Widget() { cout<<~Widget()<<endl; } ~Widget() { cout<<~Widget()<<endl; } void* operator
I'm creating a widget for which I need to calculate the minHeight and minWidth
I have a widget that sits within a stacked widget and is used to
In my custom widget, there are seven labels included as child widgets. Their texts
Main need : Resizable widget Minor need : Wide range of Android OS, runs
I have a container widget with a QVBoxLayout. I have about 100 widgets added
I have a widget with a prefs activity. In that activity the user is

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.