0

I am creating a home application and I finally got it to host widgets. The only problem is that when I change the orientation of the phone the widgets disappear and I have to add them all over again. I know that activities are recreated when the orientation changes but what should I do for the widgets to show up again?

GabeDroid
  • 677
  • 1
  • 9
  • 13

1 Answers1

0

Setting the background of an Activity

See my answer there. Just do not write anything in the onConfigurationChanged() method.

This is caused because the orintation changes restarts your activity.

Community
  • 1
  • 1
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • Does this force the activity to not restart when changing the orientation? – GabeDroid Jul 27 '11 at 22:12
  • Yep, if you do not add anything in onConfigurationChanged() method, basically you are telling you app: "DO NOT DO ANYTHING, IF ORIENTATION CHANGES" :D – Nikola Despotoski Jul 27 '11 at 22:15
  • But the problem is I have seperate layouts for landscape and portrait orientation. Won't that be a problem? – GabeDroid Jul 27 '11 at 22:26
  • And you load each based on orientation change? if you do change, then use the tests and when the orient is landscape load the landscape layout, and for portrait the portrait layout. – Nikola Despotoski Jul 27 '11 at 22:27
  • I think I might have found a better solution. Is it possible to use the onconfigurationchanged() method on a specific view rather than the entire activity or layout? – GabeDroid Jul 27 '11 at 22:32
  • You can affect that view from `onCC()` – Nikola Despotoski Jul 27 '11 at 22:42
  • If you have some particular view set it inside `LinearLayout` setting its initial orientation let say to portrait. And then you change the orientation of linearlayout using `.setOrientation()` in `onConfigurationChanged()` method.... Thus the view orientation. But if the whole (main) layout orientation changes then there is no need doing this. – Nikola Despotoski Jul 27 '11 at 23:01
  • Well the thing is that I havr widvets in a particular view and that is the only virw that I want to control the onconfigurationchanged – GabeDroid Jul 27 '11 at 23:13
  • I don't know if that is possible. Sorry. – Nikola Despotoski Jul 27 '11 at 23:15