Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using updateAppWidgetOptions method of AppWidgetManager to store per-widget customization options

I have three questions about App Widget Options:

1) If I want to add an option value to the options of an app widget, I should always first retrieve the widget options with getAppWidgetOptions(int) and then manipulate the Bundle, otherwise when I call updateAppWidgetOptions(int appWidgetId, Bundle options) I overwrite other existing options, right?

2) Do this options survive a reboot? I.e., if I store some informations related to a widget within a configuration activity, am I sure I'll ever find them even after a reboot? Does the system automagically persist them somewhere?

3) Is this faster than storing widget options in shared preferences?

like image 767
Gianni Costanzi Avatar asked Aug 06 '12 18:08

Gianni Costanzi


People also ask

What is widget host in android?

App widget host: The AppWidgetHost provides the interaction with the AppWidget service for apps that want to embed app widgets in their UI. An AppWidgetHost must have an ID that is unique within the host's own package. This ID remains persistent across all uses of the host.

Can I add Google assistant as a widget?

You can display an Android app widget in Google Assistant to fulfill these kinds of intents. This guide covers fulfilling Assistant user queries using widgets, and how to enhance your widget experience for Assistant with the App Actions Widgets Extension library.

How do you update widgets on Android?

Full update: Call AppWidgetManager. updateAppWidget(int, android. widget. RemoteViews) to fully update the widget.


2 Answers

updateAppWidgetOptions is for launchers to call to pass information to widgets. Widgets recieve this information in onAppWidgetOptionsChanged. Widgets do not store information this way, and if they try they will be overwritten by the launcher.

like image 68
j__m Avatar answered Oct 22 '22 07:10

j__m


  1. Yes, I guess so. If you want to be sure, I suppose you should just test it.

  2. I don't think so. You need persistent storage like a SQLite DB or Shared Preferences to survive a reboot

  3. Maybe, since it's memory based (SharedPrefs are file based).

like image 44
Jürgen 'Kashban' Wahlmann Avatar answered Oct 22 '22 08:10

Jürgen 'Kashban' Wahlmann