Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dmpatel151282/e038f101b7f8faa47c8fdb6a48d6aa35 to your computer and use it in GitHub Desktop.
Save dmpatel151282/e038f101b7f8faa47c8fdb6a48d6aa35 to your computer and use it in GitHub Desktop.
There are generally three ways to do this:
1. As some of the answers suggested, you could distinguish the cases of your activity being created for the first time and being restored from savedInstanceState.
This is done by overriding onSaveInstanceState and checking the parameter of onCreate.
2. You could lock the activity in one orientation by adding android:screenOrientation="portrait" (or "landscape") to <activity> in your manifest.
<activity android:screenOrientation="landscape">
3. You could tell the system that you meant to handle screen changes for yourself by specifying android:configChanges="screenOrientation" in the <activity> tag.
This way the activity will not be recreated, but will receive a callback instead (which you can ignore as it's not useful for you).
<activity
android:name=".YourActivityName"
android:configChanges="orientation|screenSize">
</activity>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment