I have an AppWidget that has a StackView in it. Along with AppWidget, I have a service that starts when a user adds my AppWidget to their desktop, which polls new data every two hours. When the service finds new data, I need it to report my AppWidget and also pass this data to the RemoteViewsService (which has RemoteViewsFactory) so that it can create the necessary views for the new data.
Currently, when the service finds new data, I passed it to AppWidget that the new data was found, passing this data as an array of integers within the intent.
My onReceive method in my AppWidgetProvider application retrieves this data, and then I go on to the process of setting up a new intent, which is passed by my RemoteViews for 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++ ) {
This works for the first time. Data is displayed using RemoteViewsService / RemoteViewsFactory. Subsequent new data does not fall into the RemoteViewsFactory constructor because the service for this factory is already running.
How do I update the data? I feel like I should use onDataSetChanged, but how do I access the intent that I passed from AppWidget onReceive?
I would be grateful for the correct way to do this. Thanks.
source share