I have an application with some AppWidget
s. I'm storing some information about every widget including its appWidgetId
inside a database - I need this information to properly update every widget. The problem is that after the device is rebooted I can't address these appWidgetId
s anymore, as it seems that they change their values. How can I overcome this problem? Thanks in advance.

- 39,695
- 10
- 113
- 130
-
Why do you need to persist the IDs? What are you using them for? Paste the relevant code. – Dheeraj Vepakomma Mar 19 '12 at 14:44
-
@Dheeraj, The appWidgetId is a key to a database table row, which stores the info needed to fetch the information from the Internet, appropriate to this single widget. What kind of code do you need to see? Will this help solving the issue? – Egor Mar 19 '12 at 14:56
-
@Dheeraj, My application is displaying currency rates for different pairs of countries. Each widget has country information bound with it, and there is an automatic update system, that needs this information to update every widget. Is there any way to resolve the problem? – Egor Mar 19 '12 at 19:10
-
@Dheeraj, Thanks! You can format your comment as an answer so I can accept it. – Egor Mar 20 '12 at 09:55
3 Answers
It looks like only on certain devices the appwidget IDs change on reboot (due to a bug). See this thread.
I looked at the Android source. The appwidget IDs are indeed persisted in a file at /data/system/appwidgets.xml
. Perhaps your device has a bug as mentioned in the thread above.
I can't think of a suitable work-around.

- 26,870
- 17
- 81
- 104
I think Dheeraj is right. I'm also a Developer of Android Widgets and do the same you do: I save the settings for each widget by remebering the WidgetId. This works flawlessly on all devices I know. The ID's do not change after reboots on all devices I know. Are you sure about your observations?

- 31,591
- 21
- 89
- 127
-
It seemed to happen at random one or two times which made me think that the appWidgetIds are somehow dropped on rebooting. Today I've fixed some database issues, and probably they were the real problem. – Egor Mar 20 '12 at 10:48
-
@Egor So the devices you thought that were problematic actually were fine, and the ids stay? – android developer Apr 13 '13 at 23:08
New appWidgetId is genrated in R.java everytime when you run the application instead of storing id from R.java you can store id from android:id="@+id/btn_add" in your database.

- 593
- 1
- 6
- 17
-
1I'm not talking about the id's of Buttons, I'm talking about the AppWidget ids. – Egor Mar 19 '12 at 14:54