[android-developers] Re: Know if your widget is on the homescreen
Thanks a lot Kostya, I was not fully aware of the onEnable(), onDisable() funcionality. It works pretty well now :) On Jun 24, 10:08 pm, Kostya Vasilyev kmans...@gmail.com wrote: Albert, 25.06.2010 0:29, Albert ?: The AppWidgetProvider is notified on every add and remove operation, along with first-add and last-remove operations. I have tried that but there are scenarios in which is does not work, the user for example could have 2 instances of the widget and then delete one... It works, first you get APPWIDGET_DELETED for the deleted widget id, then possibly APPWIDGET_DELETED for the other one (or APPWIDGET_UPDATE with some new widget id). Or, you can ask your AppWidgetManager getAppWidgetIds(). I can definetly use this. I have played a bit with the onUpdate() and onDeleted() methods and I can see a new value (id) generated for each instance of the widget, so now I can use it to know whether I have any on the homescreen, thus I will not have a service running with no widget:) There are actions just for this: http://developer.android.com/reference/android/appwidget/AppWidgetPro... public static final String ACTION_APPWIDGET_ENABLED Sent when an instance of an AppWidget is added to a host for the first time. This broadcast is sent at boot time if there is a AppWidgetHost installed with an instance for this provider. See Also AppWidgetProvider.onEnabled(Context context) public static final String ACTION_APPWIDGET_DISABLED Sent when an instance of an AppWidget is removed from the last host. See Also AppWidgetProvider.onEnabled(Context context) However, if your service is for just updating the widget, you can do startService from onUpdate(), have the service update all your widgets (using AppWidgetManager updateAppWidget (ComponentName provider, RemoteViews views)), and exit. -- Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Know if your widget is on the homescreen
Ok I found an issue here, If I add the widget and there is no room on the homescreen my widget does not get added but both onEnable() and onUpdate() get called. Then after I delete my truly last instance, appWidgetHost still thinks there is another one out there. Is there a way to get a callback somehow that the widget could not be added? Thanks On Jun 25, 9:36 am, Albert albert8...@googlemail.com wrote: Thanks a lot Kostya, I was not fully aware of the onEnable(), onDisable() funcionality. It works pretty well now :) On Jun 24, 10:08 pm, Kostya Vasilyev kmans...@gmail.com wrote: Albert, 25.06.2010 0:29, Albert ?: The AppWidgetProvider is notified on every add and remove operation, along with first-add and last-remove operations. I have tried that but there are scenarios in which is does not work, the user for example could have 2 instances of the widget and then delete one... It works, first you get APPWIDGET_DELETED for the deleted widget id, then possibly APPWIDGET_DELETED for the other one (or APPWIDGET_UPDATE with some new widget id). Or, you can ask your AppWidgetManager getAppWidgetIds(). I can definetly use this. I have played a bit with the onUpdate() and onDeleted() methods and I can see a new value (id) generated for each instance of the widget, so now I can use it to know whether I have any on the homescreen, thus I will not have a service running with no widget:) There are actions just for this: http://developer.android.com/reference/android/appwidget/AppWidgetPro... public static final String ACTION_APPWIDGET_ENABLED Sent when an instance of an AppWidget is added to a host for the first time. This broadcast is sent at boot time if there is a AppWidgetHost installed with an instance for this provider. See Also AppWidgetProvider.onEnabled(Context context) public static final String ACTION_APPWIDGET_DISABLED Sent when an instance of an AppWidget is removed from the last host. See Also AppWidgetProvider.onEnabled(Context context) However, if your service is for just updating the widget, you can do startService from onUpdate(), have the service update all your widgets (using AppWidgetManager updateAppWidget (ComponentName provider, RemoteViews views)), and exit. -- Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Know if your widget is on the homescreen
Albert, Yes, Android sometimes forgets to forget widget Ids. Also happens if a widget has a configuration activity and the user cancels. I recently ran into this, my solution is here: http://kmansoft.wordpress.com/2010/06/22/per-widget-options-stale-widgets/ -- Kostya 25.06.2010 12:44, Albert пишет: Ok I found an issue here, If I add the widget and there is no room on the homescreen my widget does not get added but both onEnable() and onUpdate() get called. Then after I delete my truly last instance, appWidgetHost still thinks there is another one out there. Is there a way to get a callback somehow that the widget could not be added? Thanks On Jun 25, 9:36 am, Albertalbert8...@googlemail.com wrote: Thanks a lot Kostya, I was not fully aware of the onEnable(), onDisable() funcionality. It works pretty well now :) On Jun 24, 10:08 pm, Kostya Vasilyevkmans...@gmail.com wrote: Albert, 25.06.2010 0:29, Albert ?: The AppWidgetProvider is notified on every add and remove operation, along with first-add and last-remove operations. I have tried that but there are scenarios in which is does not work, the user for example could have 2 instances of the widget and then delete one... It works, first you get APPWIDGET_DELETED for the deleted widget id, then possibly APPWIDGET_DELETED for the other one (or APPWIDGET_UPDATE with some new widget id). Or, you can ask your AppWidgetManager getAppWidgetIds(). I can definetly use this. I have played a bit with the onUpdate() and onDeleted() methods and I can see a new value (id) generated for each instance of the widget, so now I can use it to know whether I have any on the homescreen, thus I will not have a service running with no widget:) There are actions just for this: http://developer.android.com/reference/android/appwidget/AppWidgetPro... public static final String ACTION_APPWIDGET_ENABLED Sent when an instance of an AppWidget is added to a host for the first time. This broadcast is sent at boot time if there is a AppWidgetHost installed with an instance for this provider. See Also AppWidgetProvider.onEnabled(Context context) public static final String ACTION_APPWIDGET_DISABLED Sent when an instance of an AppWidget is removed from the last host. See Also AppWidgetProvider.onEnabled(Context context) However, if your service is for just updating the widget, you can do startService from onUpdate(), have the service update all your widgets (using AppWidgetManager updateAppWidget (ComponentName provider, RemoteViews views)), and exit. -- Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com -- Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Know if your widget is on the homescreen
Thanks Kostya for your reply, Your implementation is great, and I had something like this in mind. The onEnable() and onDisable() actually work pretty well but, there is one scenario which affects that approach and I think your approach too: The user picks your widget to add it to the screen, gets pass configuration and boom there is no room in the homescreen. You get a toast message saying No more room on this homescreen but the onEnable(), onUpdate() and your configuration screen were all successful but the widget never got added.Then next time you try the widgetId is different, meaning you have lost the last ID and you will always think that it is on the homescreen as you will never receive a onDeleted() with that ID. Note: This is happening in 1.5 and 1.6 (haven't tested on 2.0) but in 2.1 and 2.2 I see the widget call onDeleted() instantly when it fails to add due to not having room. Probably it was a bug before and the platform dev fixed now. Please let me know what you think in this case A On Jun 25, 2:16 pm, Kostya Vasilyev kmans...@gmail.com wrote: Albert, Yes, Android sometimes forgets to forget widget Ids. Also happens if a widget has a configuration activity and the user cancels. I recently ran into this, my solution is here: http://kmansoft.wordpress.com/2010/06/22/per-widget-options-stale-wid... -- Kostya 25.06.2010 12:44, Albert пишет: Ok I found an issue here, If I add the widget and there is no room on the homescreen my widget does not get added but both onEnable() and onUpdate() get called. Then after I delete my truly last instance, appWidgetHost still thinks there is another one out there. Is there a way to get a callback somehow that the widget could not be added? Thanks On Jun 25, 9:36 am, Albertalbert8...@googlemail.com wrote: Thanks a lot Kostya, I was not fully aware of the onEnable(), onDisable() funcionality. It works pretty well now :) On Jun 24, 10:08 pm, Kostya Vasilyevkmans...@gmail.com wrote: Albert, 25.06.2010 0:29, Albert ?: The AppWidgetProvider is notified on every add and remove operation, along with first-add and last-remove operations. I have tried that but there are scenarios in which is does not work, the user for example could have 2 instances of the widget and then delete one... It works, first you get APPWIDGET_DELETED for the deleted widget id, then possibly APPWIDGET_DELETED for the other one (or APPWIDGET_UPDATE with some new widget id). Or, you can ask your AppWidgetManager getAppWidgetIds(). I can definetly use this. I have played a bit with the onUpdate() and onDeleted() methods and I can see a new value (id) generated for each instance of the widget, so now I can use it to know whether I have any on the homescreen, thus I will not have a service running with no widget:) There are actions just for this: http://developer.android.com/reference/android/appwidget/AppWidgetPro... public static final String ACTION_APPWIDGET_ENABLED Sent when an instance of an AppWidget is added to a host for the first time. This broadcast is sent at boot time if there is a AppWidgetHost installed with an instance for this provider. See Also AppWidgetProvider.onEnabled(Context context) public static final String ACTION_APPWIDGET_DISABLED Sent when an instance of an AppWidget is removed from the last host. See Also AppWidgetProvider.onEnabled(Context context) However, if your service is for just updating the widget, you can do startService from onUpdate(), have the service update all your widgets (using AppWidgetManager updateAppWidget (ComponentName provider, RemoteViews views)), and exit. -- Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com -- Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Know if your widget is on the homescreen
Albert, Agree about the no space case. This is (was) definitely a bug. Found this message: http://www.mail-archive.com/android-developers@googlegroups.com/msg64867.html where Romain Guy wrote that it's fixed in the next release after 2.0 - I guess that means 2.1 -- Kostya 25.06.2010 17:42, Albert пишет: The user picks your widget to add it to the screen, gets pass configuration and boom there is no room in the homescreen. You get a toast message saying No more room on this homescreen but the onEnable(), onUpdate() and your configuration screen were all successful but the widget never got added.Then next time you try the widgetId is different, meaning you have lost the last ID and you will always think that it is on the homescreen as you will never receive a onDeleted() with that ID. Note: This is happening in 1.5 and 1.6 (haven't tested on 2.0) but in 2.1 and 2.2 I see the widget call onDeleted() instantly when it fails to add due to not having room. Probably it was a bug before and the platform dev fixed now. -- Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Know if your widget is on the homescreen
The AppWidgetProvider is notified on every add and remove operation, along with first-add and last-remove operations. I have tried that but there are scenarios in which is does not work, the user for example could have 2 instances of the widget and then delete one... Or, you can ask your AppWidgetManager getAppWidgetIds(). I can definetly use this. I have played a bit with the onUpdate() and onDeleted() methods and I can see a new value (id) generated for each instance of the widget, so now I can use it to know whether I have any on the homescreen, thus I will not have a service running with no widget :) Thanks -- Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy Android App Developer Books:http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Know if your widget is on the homescreen
Albert, 25.06.2010 0:29, Albert ?: The AppWidgetProvider is notified on every add and remove operation, along with first-add and last-remove operations. I have tried that but there are scenarios in which is does not work, the user for example could have 2 instances of the widget and then delete one... It works, first you get APPWIDGET_DELETED for the deleted widget id, then possibly APPWIDGET_DELETED for the other one (or APPWIDGET_UPDATE with some new widget id). Or, you can ask your AppWidgetManager getAppWidgetIds(). I can definetly use this. I have played a bit with the onUpdate() and onDeleted() methods and I can see a new value (id) generated for each instance of the widget, so now I can use it to know whether I have any on the homescreen, thus I will not have a service running with no widget:) There are actions just for this: http://developer.android.com/reference/android/appwidget/AppWidgetProvider.html public static final String ACTION_APPWIDGET_ENABLED Sent when an instance of an AppWidget is added to a host for the first time. This broadcast is sent at boot time if there is a AppWidgetHost installed with an instance for this provider. See Also AppWidgetProvider.onEnabled(Context context) public static final String ACTION_APPWIDGET_DISABLED Sent when an instance of an AppWidget is removed from the last host. See Also AppWidgetProvider.onEnabled(Context context) However, if your service is for just updating the widget, you can do startService from onUpdate(), have the service update all your widgets (using AppWidgetManager updateAppWidget (ComponentName provider, RemoteViews views)), and exit. -- Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en