Go directlyCode:
First Class: testactivity
Package Feb. hxy; import Feb. hxy. r. string; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. widget. button; public class testactivity extends activity {private button; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); system. out. println ("testactivity. oncreate "); button = (button) findviewbyid (R. id. anotheractivity); button. settext (string. anotheractivity); button. setonclicklistener (New button. onclicklistener () {public void onclick (view v) {intent = new intent (); intent. setclass (testactivity. this, anothpolicfti.pdf. class); startactivity (intent); testactivity. this. finish () ;}}) ;}public void onstart () {system. out. println ("testactivity. onstart "); super. onstart ();} public void onresume () {system. out. println ("testactivity. onresume "); super. onresume ();} public void onpause () {system. out. println ("testactivity. onpause "); super. onpause ();} public void onstop () {system. out. println ("testactivity. onstop "); super. onstop ();} public void ondestroy () {system. out. println ("testactivity. ondestory "); super. ondestroy ();} public void onrestart () {system. out. println ("testactivity. onrestart "); super. onrestart ();}}
The second category: anoth1_fti.pdf
Package Feb. hxy; import Feb. hxy. r. string; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. widget. button; public class anoth?fti=extends activity {private button; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); system. out. println ("anoth?fti=. oncreate "); button = (button) findviewbyid (R. id. anotheractivity); button. settext (string. back); button. setonclicklistener (New button. onclicklistener () {public void onclick (view v) {intent = new intent (); intent. setclass (anothpolicfti.pdf. this, testactivity. class); startactivity (intent); // anoth?fti=. this. finish () ;}}) ;}public void onstart () {system. out. println ("anoth?fti=. onstart "); super. onstart ();} public void onresume () {system. out. println ("anoth?fti=. onresume "); super. onresume ();} public void onpause () {system. out. println ("anoth?fti=. onpause "); super. onpause ();} public void onstop () {system. out. println ("anoth?fti=. onstop "); super. onstop ();} public void ondestroy () {system. out. println ("anoth?fti=. ondestory "); super. ondestroy ();} public void onrestart () {system. out. println ("anoth?fti=. onrestart "); super. onrestart ();}}
Run the command in the simulator and check the ddms. The following content is displayed first:
ClickProgramThe buttons in are as follows:
Also, click the button component in the second activity, as shown below:
Note:The ondestroy () method of anotheractivity is not called, because anotheractivity has commented on:
// Anoth?fti=. this. Finish ();
It can be seen that ondestroy () is called when finish () is called (). Destroy the activity.
Click the return key on the simulator. The result is as follows:
At this time, the onrestart () method of anotheractivity is called.
Remove the annotation in anotheractivity and follow the preceding steps. The running result is as follows:
Download complete code:Testandroid (Note: This program uses a simulator of 2.2)