I have a widget that is configured through an activity (I do not want to do it through a preference activity) and would like to have the configuration activity to open each and every time a widget is added.
Once the user configures the widget, the data is saved in an XML.
I see that onEnable() works only the first time a widget is added, my question is: is there any other function that is called every time a widget is added?
I have considered adding the widgetId to the XML and check every time the onUpdate() is called if there is a new widgetId that is not in the XML file, but I guess that is very messy.
Can anyone give me some hint here?
When user add new instance of your widget,
onUpdateandonReceivemethods of your AppWidgetProvider will be invoked.You can try to start Activity when those invoked.Edit:
To detect that user add new instance of your widget,you would to save
int[] appWidgetIds(this is array of unique IDs of your widget instances) whenonUpdateandonReceivemethod are invoked(probably you have to save it in App preferences or file or …).Then when onUpdate or onReceive invoked agaain,check thatlength of newest appWidgetIds is greater than length of latest appWidgetIdsor no?If it was true,you can sure that user added new instance ,if both be equal,one of your widget updated normally and if newest length be less than latest length,you can sure that user deleted on of your widget instances.InonUpdateandonReceive,Finally saveappWidgetIdsagain and so on.