In my Android application, when I rotate the device (slide out the keyboard) then my Activity
is restarted (onCreate
is called). Now, this is proba
You might also consider using the Android platform's way of persisting data across orientation changes: onRetainNonConfigurationInstance()
and getLastNonConfigurationInstance()
.
This allows you to persist data across configuration changes, such as information you may have gotten from a server fetch or something else that's been computed in onCreate
or since, while also allowing Android to re-layout your Activity
using the xml file for the orientation now in use.
See here or here.
It should be noted that these methods are now deprecated (although still more flexible than handling orientation change yourself as most of the above solutions suggest) with the recommendation that everyone switch to Fragments
and instead use setRetainInstance(true)
on each Fragment
you want to retain.