开发者

List disappears when phone rotated(Android)

开发者 https://www.devze.com 2023-03-22 17:25 出处:网络
In my app, in the OnCreate method, I create a list(using an add b开发者_Python百科utton) or I fetch it from a saved file. My function works fine and I am able to create and fetch the list until I rota

In my app, in the OnCreate method, I create a list(using an add b开发者_Python百科utton) or I fetch it from a saved file. My function works fine and I am able to create and fetch the list until I rotate the phone(vertical -> horizontal). The list then disappears. I am still able to click the buttons on screen, but it seems I have no items in the list.Any help appreciated. Thank You in advance.


add this tag in Activity tag in manifest

android:configChanges="keyboardHidden|orientation"

and add this in activity code

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);


    }

in the same activity..

this happens because each time your screen orientation is changed onCreate() method of the Activity will be called every time


This post from developer.android.com could help too!


It would be wise if you would add screenSize at android:configChanges="keyboardHidden|orientation" aswell i.e android:configChanges="orientation|keyboardHidden|screensize"

0

精彩评论

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