In my app I have got two different appwidgets.
Both show and edit the same value.
Both widgets are working fine.
My question is: how can I call the onUpdate of the second widget when I edited the value in the first one?
Thank you for the answers!
See this link
Call the updateAppWidget method of the AppWidgetManager passing in the Widget ID of the widget you want to update and the RemoteViews to update it to.
I solved my problem by using different broadcasts for each widget.
This should be the easiest solution.
Related
I'm trying to update my AppWidget from my activity.
Similar to this question:
Programmatically update widget from activity/service/receiver
I'm using AppWidgetManager to get the ids and send an update broadcast but it doesn't work for me.
I suspect that it's because my AppWidgetProvider is in a library project and thus under a different package than my main app.
Any ideas on how to make it work?
I tried all kind of contexts (this, getApplication() , etc.) , nothing worked.
(I don't get the ids of the widgets).
Thanks.
I had to use the package name of the app in component name and the full classname in the library in the class.
I would like to update my widget every time it gets resized. I figured out that this is done in:
onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions)
But I can't find out how to update the widget in it. I tried to redraw the widget by calling everything that I put in onUpdate(), but it's not working. How can I make use of the bundle?
I would like to update my widget every time it gets resized.
Cool!
I figured out that this is done in onAppWidgetOptionsChanged()
More accurately, if you have the right actions in your <intent-filter>, on Android 4.1+ devices, you will find out about resize events via onAppWidgetOptionsChanged().
But I can't find out how to update the widget in it.
You update it the same way you update it in onUpdate(). Call updateAppWidget() on the AppWidgetManager with an appropriate RemoteViews.
I tried to redraw the widget by calling everything that I put in onUpdate(), but it's not working.
"it's not working" is not a particularly effective description of your symptoms.
How can I make use of the bundle?
For a Bundle named newOptions, you can find out your new size range via:
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)
For example, this sample project contains an AppWidgetProvider that simply pours those values into a string and uses that to update a TextView. The result looks like:
I have a class which extends AppWidgetProvider, and is responsible fro showing widget.
In my onUpdate method I initialize list of widgets add put all it id's in linked list.
and I also have a method updateWidget() which is iterate through this linked list of widgets and update it every 10 seconds.
So when I have one widget instance everything works great, but when I 'am trying to add several widget I got following problems:
To add second widget to that linked list, I need first add it, then delete it, then add it again< and only after that this widget id will be added to that linked list, so only after that it will be up-datable.
What can be the issue, how can i get a normal workflow of my widget?
Thank you on advance.
It seems that you have a list of widgets (mAppWidgetList) per widget. You should probably consider changing it to a static or something.
I have answered the similar question yesterday. Please check that
Android : Alarm for update more widget
You dont have to use the widget ids to update all the instances of the widget.
Use public void updateAppWidget (ComponentName provider, RemoteViews views) to update the widget.
I would like to get a notification when the user taps/clicks on a widget?
Is there something similar to onClick()?
You must use AppWidgetProvider and register listeners there. Since in Widgets all view are created via RemoteViews you must use methods on them - e.g. setOnClickPendingIntent().
Here is a small example: http://developer.android.com/guide/topics/appwidgets/index.html#AppWidgetProvider
Can anyone give me an example of using a Stack Widget and being able to remove and add views dynamically.
Here is an example.
1) Widget loads and you add 4 views to the widget
2) User loads and activity within the same widget package and uses a button to delete one of the 4 views.
I need an example how to do that.
Thanks for the help!!
Your StackView widget should have an implemntation of the RemoteViewsService.RemoteViewsFactory interface which includes the onDataSetChanged() method. Within this method you need to update the widget from your data source.
Then in your application, any time your data set changes you can then tell any instances of your widget to refresh themselves by calling:
AppWidgetManager awm =
AppWidgetManager.getInstance(getActivity());
awm.notifyAppWidgetViewDataChanged(awm.getAppWidgetIds(new
ComponentName(getActivity(),
Your_App_Widget_Provider.class)),
R.id.your_stack_view);