-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Siddhant edited this page Mar 23, 2018
·
4 revisions
There are three ways you can do it
-
If Your apps is based on one orientation than mention that in manifest file with activity attributes
<activity android:name=".HandleDataActivity"
android:screenOrientation="portrait">
// or landscape -
If Apps are working on both the orientations, one way is that you can make changes in Android Manifest file to maintain the data with activity attribute.
<activity android:name=".HandleDataActivity"
android:configChanges="orientation|screenSize">
-
It can be done by coding using two methods which are used in activity cycle when screen rotates
- onSaveInstanceState
- onRestoreInstanceState
override fun onSaveInstanceState(outState: Bundle?)
{
`super.onSaveInstanceState(outState)`
`Toast.makeText(this,"onSaveInstanceState Method Called",Toast.LENGTH_LONG).show()`
`outState?.putString("name",""+etName?.text.toString()+" "+etMiddleName?.text.toString()+" "+etLastName?.text.toString())`
}
override fun onRestoreInstanceState(savedInstanceState: Bundle?)
{
`super.onRestoreInstanceState(savedInstanceState)`
`Toast.makeText(this,"onRestoreInstanceState Method Called",Toast.LENGTH_LONG).show()`
`setName(savedInstanceState?.getString("name","").toString())`
}