On Change Screen Orientation, New Activity Created
I'm relatively new to Android but have made quite a few apps over the past year so forgive me. I know that when you are running an app on a device and change the screen orientation
Solution 1:
In your AndroidManifest.xml add, android:configChanges and this would avoid the activity being re-created on orientation change. I hope your landscape and portrait mode has the same layout.
<activityandroid:label="Your Activity Name"android:configChanges="keyboardHidden|orientation|screenSize"android:name="com.yourpackage">
To add more to this, i would suggest you to look at the onPause()
and onResume()
methods and if you are playing with Fragments then have a watch on onSaveInstanceState
and onRetainInstanceState
rather than applying the xml changes as "Activity is destroyed by design."
http://developer.android.com/training/basics/activity-lifecycle/index.html
Solution 2:
If you are worried about losing the value of local variables within your activity... You could use Singleton Pattern for some of those variables. This not a beautiful solution, but could work.
Post a Comment for "On Change Screen Orientation, New Activity Created"