I have an application in which I programmatically create a view EditText. I assign an identifier to this view withsetId()
myEditText.setId(100);
so Android automatically saves this state of the object when the application is paused / stopped (as I was recommended to do here ). It works in the following cases:
- (1) When I leave the application using the "Home" button: if I return to the application, the state of the object (displayed text) will be restored, as expected.
- (2) When the screen orientation changes (in which Android automatically destroys the activity and restores it through
Bundle). The state of the object is also saved.
However, in this case does not work :
- (3) When I leave the application using the back button: if I return to the application, the object is
EditTextempty.
Any explanation of why this is happening? Does Android have an excellent app shutdown with Home and Back? According to the documentation , the state of the object should be saved automatically through Bundle, even if the action is destroyed. And this obviously happens in case (2). But not in the case of (3)!
, , "" ? , SharedPreferences , , Android , (1) (2).
, , Android 4.0 4.2 ( ).