When calling another class can you make the initial class remain in state
I have two classes class 1 and class 2.
Within class 1 I have an onclick button which calls the next class using the following:
Intent StartGameIntent = new Intent(StartGame.this,class2.class);
startActivity(StartGameIntent);
Is there anyway to make class 1 remain in state. so when I call class 1 from class 2, class one w开发者_运维知识库ill still show what was originally there?
Thanks
You should be able to call your new class2 with and Intent and do not call finish(); on class1. When the user selects something that calls finish(); on class2, class1 will still be running as you left it in the background and come forward again. If the users presses 'back' it should also work.
If they press 'home' and you wanted to save the state then you will want to look at the Android Activity Life-Cycle and look at saving your settings/application state in something like onPause.
This is normally done via Activity.onSaveInstanceState and onRestoreInstanceState.
See
http://developer.android.com/reference/android/app/Activity.html#onRestoreInstanceState(android.os.Bundle) http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)
精彩评论