[android-developers] Re: Screen rotation with App Widgets loses onClick connection
Hi ! I seem to have the same problem but the solution I've found everywhere on the web and in this thread does not work for me :( I posted my onUpdate method below, in which I perform a full initialisation of a new RemoteViews object. Then I pass it to the AppWidgetManager. This kind of operation (init + call to updateAppWidget) is done only in one place in whole my application : in this onUpdate method. Thus, I never send an incomplete RemoteViews object. This is why I don't understand why I suffer from the same screen orientation change problem :'( I tried to call the onUpdate method from the onReceive method, and it works fine, but I think this solution is dirty, especially because I make this additional call to onUpdate on every call to onReceive (I cannot filter on some kind of on screen orientation changed message). Here is the onUpdate method : @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); // Mise à jour de l'image dans les widgets updateClockinImage(context,appWidgetIds, getCheckingCount(context)); // Build the intent to call the service final Intent intent = new Intent(context.getApplicationContext(), AddCheckingService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); // Pour réagir à un clic il faut utiliser une pending intent car le onClickListener // est exécuté par l'application Home final PendingIntent pendingIntent = PendingIntent.getService(context.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.btn_checkin, pendingIntent); // Mise à jour des widgets avec le nouvel intent appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); super.onUpdate(context, appWidgetManager, appWidgetIds); } Thanks in advance !!! Le vendredi 14 janvier 2011 06:26:43 UTC+1, John Gaby a écrit : I have an App Widget on the Home screen which works fine until the screen is auto-rotated. At that point, the onClick connection (set up via a call to setOnClickPendingIntent) is lost. The only way I seem to be able to get it back is to delete the Widget from the Home screen and then add it back. Is there some kind of message that tells me that the screen has rotated that I need to respond to (and reestablish the connection)? Thanks -- 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: Screen rotation with App Widgets loses onClick connection
Each and every update you push to the wigdget with RemoteViews has to have complete widget state, including all images, text, and pending intents. There is no onUpdate on configuration changes. The home screen recreates your widget, then takes the most recent RemoteViews and applies it to the widget. If your codes tries to update the widget incrementally, piece-by-piece, with one RemoteViews specifying the intent, and another, repeated, update setting some changing information, then you end up with the most recent RemoteViews only having your changing text, but no PendingIntent. This is very much unlike how Activities work, where the entire view hierarchy is kept in memory for as long as the activity is on the screen (and maybe longer). -- Kostya 2011/1/14 Anbu anbu.ezhi...@gmail.com It is because, the widget becomes unresponsive when the display mode is changed from portrait to landscape. I had the same issue and I what I had done is for every RemoteView update I had send all the pendingintent to make it work On Jan 14, 4:26 pm, John Gaby jg...@gabysoft.com wrote: I have an App Widget on the Home screen which works fine until the screen is auto-rotated. At that point, the onClick connection (set up via a call to setOnClickPendingIntent) is lost. The only way I seem to be able to get it back is to delete the Widget from the Home screen and then add it back. Is there some kind of message that tells me that the screen has rotated that I need to respond to (and reestablish the connection)? Thanks -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- 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: Screen rotation with App Widgets loses onClick connection
There is no onUpdate on configuration changes. The home screen recreates your widget, then takes the most recent RemoteViews and applies it to the widget. I figured that it was recreating the Widget on rotation. The problem is, I don't seem to be getting any messages to that effect, and have no way (that I can see) of re-establishing the connection. How can I determine that a rotate has happened and set up a new onClick connection? Thanks On Jan 14, 1:28 am, Kostya Vasilyev kmans...@gmail.com wrote: Each and every update you push to the wigdget with RemoteViews has to have complete widget state, including all images, text, and pending intents. There is no onUpdate on configuration changes. The home screen recreates your widget, then takes the most recent RemoteViews and applies it to the widget. If your codes tries to update the widget incrementally, piece-by-piece, with one RemoteViews specifying the intent, and another, repeated, update setting some changing information, then you end up with the most recent RemoteViews only having your changing text, but no PendingIntent. This is very much unlike how Activities work, where the entire view hierarchy is kept in memory for as long as the activity is on the screen (and maybe longer). -- Kostya 2011/1/14 Anbu anbu.ezhi...@gmail.com It is because, the widget becomes unresponsive when the display mode is changed from portrait to landscape. I had the same issue and I what I had done is for every RemoteView update I had send all the pendingintent to make it work On Jan 14, 4:26 pm, John Gaby jg...@gabysoft.com wrote: I have an App Widget on the Home screen which works fine until the screen is auto-rotated. At that point, the onClick connection (set up via a call to setOnClickPendingIntent) is lost. The only way I seem to be able to get it back is to delete the Widget from the Home screen and then add it back. Is there some kind of message that tells me that the screen has rotated that I need to respond to (and reestablish the connection)? Thanks -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- 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: Screen rotation with App Widgets loses onClick connection
[see below] 2011/1/14 John Gaby jg...@gabysoft.com There is no onUpdate on configuration changes. The home screen recreates your widget, then takes the most recent RemoteViews and applies it to the widget. I figured that it was recreating the Widget on rotation. The problem is, I don't seem to be getting any messages to that effect, and have no way (that I can see) of re-establishing the connection. How can I determine that a rotate has happened and set up a new onClick connection? Like I said, you don't (determine or respond to an orientation change). What you do, is make sure that every time your code pushes a RemoteViews object into the home application for your widget, it's complete in all respects: - Has image resource ids; - Has text stings; - Has pending intents. Don't do incremental widget updates, like you would do with a regular activity - don't set the intents first, then the images, then the text reflecting current information. The home app runs as a separate process, and its state can get out-of-step with your widget receiver. When it does, the only thing it has for re-creating your widget is your most recent RemoteViews object. If it's complete, and has all the parts, everything will work just fine. If it only has the most recent text or image change, the earlier updates which had the intents will be lost. http://kmansoft.wordpress.com/2010/05/23/widgets-and-orientation-changes/ -- Kostya Thanks On Jan 14, 1:28 am, Kostya Vasilyev kmans...@gmail.com wrote: Each and every update you push to the wigdget with RemoteViews has to have complete widget state, including all images, text, and pending intents. There is no onUpdate on configuration changes. The home screen recreates your widget, then takes the most recent RemoteViews and applies it to the widget. If your codes tries to update the widget incrementally, piece-by-piece, with one RemoteViews specifying the intent, and another, repeated, update setting some changing information, then you end up with the most recent RemoteViews only having your changing text, but no PendingIntent. This is very much unlike how Activities work, where the entire view hierarchy is kept in memory for as long as the activity is on the screen (and maybe longer). -- Kostya 2011/1/14 Anbu anbu.ezhi...@gmail.com It is because, the widget becomes unresponsive when the display mode is changed from portrait to landscape. I had the same issue and I what I had done is for every RemoteView update I had send all the pendingintent to make it work On Jan 14, 4:26 pm, John Gaby jg...@gabysoft.com wrote: I have an App Widget on the Home screen which works fine until the screen is auto-rotated. At that point, the onClick connection (set up via a call to setOnClickPendingIntent) is lost. The only way I seem to be able to get it back is to delete the Widget from the Home screen and then add it back. Is there some kind of message that tells me that the screen has rotated that I need to respond to (and reestablish the connection)? Thanks -- 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.comandroid-developers%2bunsubscr...@googlegroups.com android-developers%2bunsubscr...@googlegroups.comandroid-developers%252bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- 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: Screen rotation with App Widgets loses onClick connection
Got it, thanks! On Jan 14, 8:27 am, Kostya Vasilyev kmans...@gmail.com wrote: [see below] 2011/1/14 John Gaby jg...@gabysoft.com There is no onUpdate on configuration changes. The home screen recreates your widget, then takes the most recent RemoteViews and applies it to the widget. I figured that it was recreating the Widget on rotation. The problem is, I don't seem to be getting any messages to that effect, and have no way (that I can see) of re-establishing the connection. How can I determine that a rotate has happened and set up a new onClick connection? Like I said, you don't (determine or respond to an orientation change). What you do, is make sure that every time your code pushes a RemoteViews object into the home application for your widget, it's complete in all respects: - Has image resource ids; - Has text stings; - Has pending intents. Don't do incremental widget updates, like you would do with a regular activity - don't set the intents first, then the images, then the text reflecting current information. The home app runs as a separate process, and its state can get out-of-step with your widget receiver. When it does, the only thing it has for re-creating your widget is your most recent RemoteViews object. If it's complete, and has all the parts, everything will work just fine. If it only has the most recent text or image change, the earlier updates which had the intents will be lost. http://kmansoft.wordpress.com/2010/05/23/widgets-and-orientation-chan... -- Kostya Thanks On Jan 14, 1:28 am, Kostya Vasilyev kmans...@gmail.com wrote: Each and every update you push to the wigdget with RemoteViews has to have complete widget state, including all images, text, and pending intents. There is no onUpdate on configuration changes. The home screen recreates your widget, then takes the most recent RemoteViews and applies it to the widget. If your codes tries to update the widget incrementally, piece-by-piece, with one RemoteViews specifying the intent, and another, repeated, update setting some changing information, then you end up with the most recent RemoteViews only having your changing text, but no PendingIntent. This is very much unlike how Activities work, where the entire view hierarchy is kept in memory for as long as the activity is on the screen (and maybe longer). -- Kostya 2011/1/14 Anbu anbu.ezhi...@gmail.com It is because, the widget becomes unresponsive when the display mode is changed from portrait to landscape. I had the same issue and I what I had done is for every RemoteView update I had send all the pendingintent to make it work On Jan 14, 4:26 pm, John Gaby jg...@gabysoft.com wrote: I have an App Widget on the Home screen which works fine until the screen is auto-rotated. At that point, the onClick connection (set up via a call to setOnClickPendingIntent) is lost. The only way I seem to be able to get it back is to delete the Widget from the Home screen and then add it back. Is there some kind of message that tells me that the screen has rotated that I need to respond to (and reestablish the connection)? Thanks -- 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.comandroid-developers%2bunsubscr...@googlegroups.com android-developers%2bunsubscr...@googlegroups.comandroid-developers%252bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- 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: Screen rotation with App Widgets loses onClick connection
It is because, the widget becomes unresponsive when the display mode is changed from portrait to landscape. I had the same issue and I what I had done is for every RemoteView update I had send all the pendingintent to make it work On Jan 14, 4:26 pm, John Gaby jg...@gabysoft.com wrote: I have an App Widget on the Home screen which works fine until the screen is auto-rotated. At that point, the onClick connection (set up via a call to setOnClickPendingIntent) is lost. The only way I seem to be able to get it back is to delete the Widget from the Home screen and then add it back. Is there some kind of message that tells me that the screen has rotated that I need to respond to (and reestablish the connection)? Thanks -- 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