I apologize for my English but translated with google. I'd like to understand why Google with Android restarts the activity at each change and you lose all the data displayed. How do you solve this problem? Could not they make it optional this thing? On every forum I read to use the methods onSaveInstanceState, onRestoreInstanceState, onConfigurationChanged, but how to use them is not explained well. If I have a complex application, with many objects, with EditText, with Markers, Polygons, I'm forced to save everything by hand with temporary variables? There is another way faster and easier to do it? Do you have any practical example to show me? I hope you know help me understand, thank you all.
Asked
Active
Viewed 33 times
1 Answers
0
It is an optional thing. In your manifest, add android:configChanges="orientation|screenSize" to your activity and it will turn off that behavior.
Really there's only 1 good circumstance to not override it- if you have no AsyncTasks, no Threads, no Loaders, no bound services, AND you have separate layout.xml files for landscape and portrait. That's about the only time it doesn't cause more pain to recreate than it saves. It's google's biggest screwup in the API.

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
if a smartphone goes into standby or the user locks it, even in that case the activity restarts. For the rotation I already solved by putting that code in the manifest. – itc.opra Feb 18 '15 at 00:04
-
No, it really doesn't. It goes into onStop, but it does NOT restart the activity. If you're seeing that, something else is going on. Do you have the special developer option "Do not keep activities" turned on? – Gabe Sechan Feb 18 '15 at 00:05
-
That option is not active . This situation is creating me a lot of problems , because the application is complex and I can not memorize everything manually . – itc.opra Feb 18 '15 at 00:18
-
Then something else is going on. That is NOT normal behavior. Normal behavior on going to sleep is for onStop to be called, but then onStart to be called when it wakes up, without destroying the activity (onCreate will not be called). – Gabe Sechan Feb 18 '15 at 00:26