Reputation: 81
If i use the code below will this restore text that has been input into EditTextfields and selected spinner items?
@Override
protected void onPause(){
super.onPause();
}
@Override
protected void onResume(){
super.onResume();
}
or do I have to tell it to save the current values and then restore then when activity is resumed? when I am using the emulator if I don't have these methods in and I go to say home then run my app again it always loads back to the previous state, so my questions is does this actually do antyhing?
Upvotes: 0
Views: 485
Reputation: 8533
You only need to save state when onDestroy()
is called. That only happens when you use the back button or the OS kills the Activity
when it is in a stopped state.
If you Activity
becomes partially obscured it will be paused but if it is completely obscured it will be stopped.
When it is top of the stack again it will resume or start.
To experiment use Log
to write messages to the LogCat
when each of events occurs and then you will be able to see when and why they are called.
Upvotes: 0
Reputation: 1501
You values still the same in your spinner because the app hasn't been kill yet. It's only put a pause state still in memory. If the app were destroyed the values of your spinner will be back to the onCreate method and whatever value they had at the start.
Look here for what each method does --> https://developer.android.com/reference/android/app/Activity.html
Upvotes: 0
Reputation: 274
Nope, this actually only called the super class onPause() and onResume() without doing anything else. The value in your editbox stay there because even if the app is paused, is still there on the activity stack waiting. However Android can kill your paused activity and your data will be lost. So you have to save them onPause and restore them on the onResume to avoid this.
Upvotes: 1
Reputation: 36312
No, this code does not do anything. You're overriding these methods, but giving them an implementation of just calling the parent implementation. This is the same as not overriding them in the first place.
It's not absolutely necessary to save/restore state for when you pause/resume. The only reason why you would need to manually do some state saving is if you want to restore state even after your application is killed.
Upvotes: 1