I have some problems with my widgets. Here is the description:
Context:
I have a home widget.
When I add it, it pops a configuration Activity for setting some parameters for the widget.
If I call setResult(RESULT_OK, resultValue); before finishing the configuration Activity, the widget is added to the Home.
If I delete the widget by dragging it to the trash bin, public void onDeleted(Context context, int[] appWidgetIds) from my AppWidgetProvider class gets called. So far so good.
Problem: If the configuration Activity exits with result code RESULT_CANCELED (setResult(RESULT_CANCELED);), public void onDeleted(Context context, int[] appWidgetIds) from my AppWidgetProvider class is not called and the widget remains in the active widgets list. When I restart the phone, onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) from my AppWidgetProvider class is called and in int[] appWidgetIds I have all widgets (the ids) that supposed to be canceled (deleted before being added) + the active ones (the ones that are actually displayed on Home). The Widgets that were deleted by dragging to the trash bin are not displayed in this list. With time this list of widgets ids keeps getting bigger and bigger if the user is canceling from the configuration Activity.
The API reference says something like: "If you return RESULT_OK using Activity.setResult(), the AppWidget will be added, and you will receive an ACTION_APPWIDGET_UPDATE broadcast for this AppWidget. If you return RESULT_CANCELED, the host will cancel the add and not display this AppWidget, and you will receive a ACTION_APPWIDGET_DELETED broadcast."
Can anyone give me some hints on this? Thank you.
Here is my manifest:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<receiver android:name=".MytWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/my_widget_provider" />
</receiver>
<activity android:name=".ConfigurationActivity">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
</application>
The rest of the code is not relevant since it was explained above (and I don't have permission to post it).