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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:02:41+00:00 2026-05-25T13:02:41+00:00

I have an AppWidget that has a StackView contained within it. Along with the

  • 0

I have an AppWidget that has a StackView contained within it. Along with the AppWidget, I have a service that is started when a user adds my AppWidget to their homescreen that polls for new data every two hours. When the service finds new data, I need for it alert my AppWidget, and also pass that data to the RemoteViewsService (which has my RemoteViewsFactory) so that it can create the necessary views for the new data.

Currently, when the service finds new data, I have it broadcast to my AppWidget that new data has been found, passing that data as an array of integers within an intent.

My onReceive method in my AppWidgetProvider pulls that data out, and I then go through the process of setting up a new intent that is passed to my RemoteViews for the AppWidget. Sample code below:

public void onReceive( Context context, Intent intent )
{
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds( new ComponentName( context,  SampleAppWidgetProvider.class ) );

    int[] sampleData = intent.getIntArrayExtra( Intent.EXTRA_TITLE );
    for ( int i = 0; i < appWidgetIds.length; i++ )
    {
        // RemoteViewsFactory service intent
        Intent remoteViewsFactoryIntent = new Intent( context, SampleAppWidgetService.class );
        remoteViewsFactoryIntent.putExtra( AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i] );
        remoteViewsFactoryIntent.setData( Uri.parse( remoteViewsFactoryIntent.toUri( Intent.URI_INTENT_SCHEME ) ) );
        remoteViewsFactoryIntent.putExtra( Intent.EXTRA_TITLE, sampleData );

        RemoteViews rv = new RemoteViews( context.getPackageName(), R.layout.widget_layout );

        // Sync up the remoteviews factory
        rv.setRemoteAdapter( appWidgetIds[i], R.id.sample_widget, remoteViewsFactoryIntent );           
        rv.setEmptyView( R.id.sample_widget, R.id.empty_view );

        appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
    }

    super.onUpdate( context, appWidgetManager, appWidgetIds );
}

This works the first time. The data is displayed by the RemoteViewsService/RemoteViewsFactory. Subsequent new data doesn’t hit the RemoteViewsFactory’s constructor because the service for that factory is already running.

How do I go about updating the data? I feel like I should be using onDataSetChanged, but how would I access the intent that I passed from the AppWidget’s onReceive?

I’d appreciate any insight as to how to go about this properly. Thanks.

  • 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-25T13:02:41+00:00Added an answer on May 25, 2026 at 1:02 pm

    My solution to an integer array being passed to the RemoteViewsFactory was solved using a BroadcastReceiver. I extended my RemoteViewsFactory to implement the BroadcastReceiver (specifically onReceive), and registered it with my application in the constructor for the factory (this also means I unregistered it in the onDestroy). With that, I was able to broadcast the intent with the integer array that I had in the onReceive of my AppWidgetProvider and receive it within the RemoteViewsFactory.

    Make sure to also call the AppWidgetManager’s notifyAppWidgetViewDataChanged so that the RemoteViewsFactory knows that the data it was using previously has been invalidated and a new integer array is presented to create new RemoteViews off of.

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

Sidebar

Related Questions

I have a Button on appwidget, that I need to 'enable'/'disable' programmatically from a
I'm having trouble starting a Service to update an AppWidget that I'm creating as
I'm writing an AppWidget where I first have a configure screen where the user
I have an Android widget that has a configure activity. I also have an
I have created an AppWidget for Honeycomb which is working well, except that when
i have three classess.activity,service and appwidget. i have two buttons in appwidget. and onclicking
I have a widgetProvider . I also have a service class that does the
I have an application which has an Appwidget. All works well. Now I have
I have a Widget i am working on, that allows the user to have
Have just started using Google Chrome , and noticed in parts of our site,

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.