Question

I have an Android app that begins by displaying a dialog. When I set the orientation to portrait and run on an Android 3.1 emulator, the dialog is displayed, but once the user dismisses it, it is displayed again. This doesn't happen on the 3.2 emulator or if the orientation isn't set. How do I prevent the dialog from being displayed twice on Android 3.1 with the orientation set to portrait?

Here's the code:

public class TestActivity extends Activity {    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        showDialog(0);
    }

    protected Dialog onCreateDialog(int id) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Message.")
            .setPositiveButton("Ok.", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // nothing
                }
            });         
        return builder.create();
    }
}

Here is the manifest:

<uses-sdk android:minSdkVersion="7" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TestActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

When my emulator opens, it's in landscape, if that matters.

Was it helpful?

Solution

I found this: android:configChanges. Hope it helps you :-)

E.g:

<activity
    ...
    android:configChanges="orientation|keyboardHidden"" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top