My question is: how can I determine if my widget is already placed on the home screen? For example: I added the widget for the first time, and when I try to add it again, in onUpdate() method, I want to execute come code. Something like
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
if(widget_already_exists){
//do something
}
}
Is there any way to do that?
Thanks. Alex Ady*
Keep track of your app widget IDs. When you see a new one in
onUpdate()and you already had one, then the user is adding a second instance. Don’t forget to remove them from your log inonDeleted()of yourAppWidgetProvider.