Reputation: 7415
Do the ids in the array appWidgetIds of the method
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
all belong to my app?
If so then there are some appwidgets somewhere in the nirvana of my android, because if I delete all appwidgets there still remain some ids in the array which are not shown on my homescreen. :-(
Is there a way to remove ALL widgets?
Upvotes: 4
Views: 1660
Reputation: 9323
Weeelp, I've returned to Android development 8 years later (was surprised to find I already commented on this question), and now I have a real answer. It seems to have only become better-known years after this question was originally posted, but basically: There's a bug in Android that's remained unfixed pretty much forever.
All those phantom IDs are the appWidgetIds of widgets you started to creat at some point, but were incorrectly canceled on the widget configuration activity.
Over on the developer documentation, it includes this code sample for confirming creation of an widget:
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
Read the tip below it carefully:
Tip: When your configuration Activity first opens, set the Activity result to RESULT_CANCELED, along with EXTRA_APPWIDGET_ID, as shown in step 5 above. This way, if the user backs-out of the Activity before reaching the end, the App Widget host is notified that the configuration was cancelled and the App Widget will not be added.
While Android accepts setResult(RESULT_CANCEL);
(and plenty of tutorials use it and I believe even the official documentation once had sample code like this), it's wrong. Without passing along the new ID, it remains in the system as one of those mysterious phantom IDs.
The correct way to cancel creating a widget is setResult(RESULT_CANCEL, resultValue);
Upvotes: 5
Reputation: 7415
I got it solved: I uninstalled, then reinstalled my app and after that all the ghost widgets were gone.
In conclusion: all the ids in appWidgetIds are the ids of my app.
Upvotes: 1
Reputation: 7614
ur app widget can have multiple widgets for the same app, say one widget showing location, one widget showing stocks, one widget showing blah blah, in such cases, each widget can be assigned an ID called appWidgetID
Upvotes: 1