Original: http://blog.csdn.net/w709835509/article/details/7655240
1 Importandroid.app.Activity;2 ImportAndroid.os.Bundle;3 4 Public classMainactivityextendsActivity {5 //Initialize operations here, such as interface loading and event binding6 @Override7 Public voidonCreate (Bundle savedinstancestate) {8 Super. OnCreate (savedinstancestate);9 if(Savedinstancestate! =NULL) {Ten //Recovering temporary data OneString TempData = savedinstancestate.getstring ("Key"); A // ... - } - } the - //Save temporary data here - @Override - Public void onsaveinstancestate(Bundle outstate) { + Super. Onsaveinstancestate (outstate); - //The active a->b,a is in a stopped state and may be reclaimed by the system, at which point the back key still returns to a, but the OnCreate method of a is called instead of Onrestart, and the temporary data will no longer exist, such as interface data + //with this parameter of bundle, temporary data can be saved, various put ...; When a is created, it is possible to remove the data from the bundle and perform related operations, such as: AString TempData = "This is temp data"; atOutstate.putstring ("Key", tempdata); - } - - //Restart call, changed from stop state to run state - @Override - Public voidOnrestart () { in Super. Onrestart (); - //when you know that the activity in this process is already visible, load the change to } + - //called when the visible lifetime begins the @Override * Public voidOnStart () { $ Super. OnStart ();Panax Notoginseng } - the //the activity is ready to interact with the user--at the top of the stack. + @Override A Public voidOnresume () { the Super. Onresume (); + //It is said that any paused UI updates, threads, or processes needed to recover the activity, but suspend them when inactive - } $ $ //Activity is still visible when the activity is paused, such as when a dialog box pops up and the activity is paused - @Override - Public void onPause() { the //It is said that when an activity is not active in the foreground, the UI updates, threads, or CPU-intensive processes that do not need to be updated are suspended. - Super. OnPause ();Wuyi //that is, release the CPU resources, save the key data, but the action must be fast, otherwise affect the new stack top activity the } - Wu //activity is completely invisible - @Override About Public void onStop() { $ //It is said that when the process is not visible, the remaining UI updates, threads, or processes that are not needed are suspended, all edits are saved, or - //status changes because the process may be destroyed (thus releasing resources for other processes) - Super. OnStop (); - } A + //called at the end of the full lifetime the @Override - Public voidOnDestroy () { $ //empty all resources, including ending threads, shutting down database connections, and so on. the Super. OnDestroy (); the } the the}
Life cycle of android--activities