On rotating screen, it seems activity is getting restarted, it loses all it's state. I checked android developer guide.Handling Runtime Changes. It has mention about how to handle screen orientation and using onSaveInstanceState()
before it destroys your activity and restore the state during onCreate()
or onRestoreInstanceState()
.
Screen orientation lock For Android, open the AndroidManifest. xml file and within the activity element add 'android:screenOrientation="portrait"' to lock to portrait or 'android:screenOrientation="landscape"' to lock to landscape.
on iOS you need to allow your app to rotate. In XCode you need to go to target and then in the Deployment Info -> Device Orientation enable the orientaitons your app should support. For android you'll have to modify your AndroidManifest file and set the screenOrientation on the activity tag.
The screen orientation attribute is provided by the activity element in the Android Manifest. Xml file. The orientations provided by the activity are Portrait, Landscape, Sensor, Unspecified and so on. To perform a screen orientation activity you define the properties in the Android Manifest.
I am answering to my question this is how it worked for me, if anyone is facing same problem, then edit your AndroidManifest.xml on android/app/src/main and local-cli/generator-android/templates/src/app/src/main
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
Here is a detailed explanation of how to save/retrieve activity instance in Android
https://web.archive.org/web/20160308105435/http://www.intertech.com/blog/saving-and-retrieving-android-instance-state-part-1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With