Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widget onUpdate() is not called when Android home screen rotates

Tags:

android

widget

I'm currently having issues with my widget. I'm using a Droid 2 phone and when I open the keyboard the screen rotates and my widget never calls the onUpdate() function call.

In efforts to debug the issue I overwrote the onReceive() and noticed that after the screen is rotated I get the intent action:

com.motorola.blur.home.ACTION_WIDGET_ADDED

After the rotation of the screen the TextViews loose their content so I need to be able to set text after the rotation. I usually set the text at the onUpdate() call.

Anyone have any ideas why this issue? I'm sure I'm doing something wrong...

Thanks,

-Jona

like image 300
Jona Avatar asked Feb 14 '11 18:02

Jona


1 Answers

After a lot of testing and searching online I realized something so important about Widgets.

When the screen is rotated and the widget needs to be restored the Android system will restore it using the data from the last RemoteViews update.

I was updating parts of the widget separately so when it needed to restore only one part got updated.

The fix is always update everything on your RemoteViews all at once.

like image 199
Jona Avatar answered Nov 15 '22 00:11

Jona