开发者

Show AlertDialog on Activity start, but not on screen orientation change?

开发者 https://www.devze.com 2023-01-11 15:01 出处:网络
It seems when screen orientation changes, the activity\'s onCreate() method is called. In my onCreate() method, I have an AlertDialog which pops up when the activity is called. The problem is when I s

It seems when screen orientation changes, the activity's onCreate() method is called. In my onCreate() method, I have an AlertDialog which pops up when the activity is called. The problem is when I switch the screen sideways, the popup is displayed again.

How c开发者_如何学运维an I avoid this?


Modify your AndroidManifest with:

android:configChanges="orientation|keyboardHidden"

Your Activity should look like this:

<activity android:name=".activities.MyActivity"
                  android:label="@string/my_activity_name"
                  android:configChanges="orientation|keyboardHidden"/>

This will avoid the call to onCreate() when there is a change in the orientation.

0

精彩评论

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