I have a bit of a strange bug with a widget I've coded- after the screen rotates the widget stops responding to onClick events. The code is exactly the same as in the Android Developer Documentation for App Widgets here. I've noticed other widgets from the market don't have this problem- is there a known workaround perhaps? I've tried tapping all over the place after a rotation so I don't think its the onClickPendingIntent not being resized after a rotation; it doesn't seem to be present at all.
I can't find an onRotation() kind of trigger for the AppWidgetProvider to redo the listening code in the event of a rotation so I'm quite unsure how to proceed...
Thanks!
I received the following response from a post I made on Google Groups which resolved my issue. I cannot say whether it would resolve the original poster's problem, but I though I would post it, in case someone else runs across this problem. The link to my Google Groups post is:
http://groups.google.com/group/android-developers/browse_thread/thread/ca8c2958b6dc086c#
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:
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
Firstly, ensure that your RemoteViews is a FULL representation of the state of the widget if you're calling
AppWidgetManager.updateAppWidget()
. Set up all pending intents, view data, etc. This state will be re-used when the launcher wants to restore your widget from state, eg. when rotation changes.When you want to update your remote views but you don't want to supply a complete RemoteViews representation, ie. you just want to change an existing remoteView state, you may use
AppWidgetManager.partiallyUpdateAppWidget()
.For example, when advancing a ViewPager for a widget outside of onUpdate:
The following code seems like being able to resolve the problem.