开发者

Why is it that when I swap to landscape, my changes to the User Interface are undone?

I have another question!

I have a configure Activity in my app. On it, I have a ListView. Now adding & removing items to & from it works, but when I rotate the screen to landscape or back, all added & non-saved items in the ListView get removed... I wonder why this is... Wh开发者_开发知识库y is this?


When screen orientation changes, by default, the activity will be destroyed and create again. That means, the onCreate will be called again once the orientation changed. There are basically two way to solve your problem:

  1. Save your activity state before destory and load it back when create
  2. Set the Activity in AndroidManifest that not to handle screen orientation change.

E.g.

<activity name="..."
    android:configChanges="orientation" .../>


When you rotate the handset, the onStart method of you Activity is invoked. Check maybe you do some sort of initialization there.


I've solved it partially. Now it is able to hold on to the changes when changing to landscape view, but not the other way back to the normal view. I did it through the use of protected void onSaveInstanceState(Bundle saveState). But as I said, this doesn't work when it changes back from Landscape... Anybody got any ideas about this?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜