After removing my last appWidget instance from home screen, onDisabled
, onEnabled
not working.
I register my widget as a broadcast receiver, there is no instance on home screen but broadcast receives and also I see my logs that written in my appWidget core class!
After uninstalling my application and installing it again, the problem solved and onDisabled
, onEnabled
worked correctly after adding(removing) first(last) instance.
I gathered appWidgetIds manually and holding it in a file to provide some better way to access all my widgets ids, but the hidden appWidget not removed from my collected widget ids and also exist in home screen!
The Question:
Is the problem a bug on Android Version 2.3.4(Testing Device)? and in this case what is the solution?
Important part of codes:
@Override
public void onEnabled(Context context) {
G.logger.out("Enabled");
super.onEnabled(context);
}
@Override
public void onDisabled(Context context) {
super.onDisabled(context);
G.logger.out("Disabled");
File file = new File(G.infoDir + "/" + getClass().getSimpleName() + ".dat");
if (file.exists()) {
file.delete();
}
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
WidgetProperty property = G.widgetPropertyMap.get(getClass().getSimpleName());
property.appWidgetIds = appWidgetIds;
addWidgetIds(appWidgetIds, getClass().getSimpleName()); // add widget ids to a file ( duplicates will skip )
updateAll(getClass(), context);
}
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
G.logger.out("Deleted");
removeWidgetIds(appWidgetIds, getClass().getSimpleName()); // remove widget ids from file
}