Activity Life cycle
Life cycle from Creation to destruction:
OnCreate () →onstart () →onresume () →onpouse () →onstop () →ondestroy ()
From start to backstage to front desk:
OnCreate () →onstart () →onresume () →onpouse () →onstop () →onrestart () →onstart () →onresume ()
Start a second activity
1. Create New activity
2. Create a corresponding new XML layout file
3. Setcontentview (r.layout.new XML) in new activity;
4. Register the new activity in the androidmainfest.xml, including changing the Name property, the intent_filter is the first start page
In the original <activity ... Add new/> Under the
<activity android:name= ". Demo_act" android:theme= "@android: Style/theme.devicedefault.dialog" New Intent (Second. this, first. class ); startactivity (intent); ----------------------------------------------------no return value
1. Intent: Intent to assist in the completion of communication between various Android components
2.
①startactivity (Intent)
②startactivityforresult (Intent,requestcode)//have return value
Onactivityresult (int requestcode,intresultcode,intent data)//Receive return value a page
Setresult (Resultcode,data)//Set return value B page
Section 1 kind of Method
Ntent Intent = newintent (Second.this,first.class);
startactivity (intent);---------------------------------------------------- no return value
Section 2 kind of Method
1Bt2.setonclicklistener (NewView.onclicklistener () {2 @Override3 Public voidOnClick (View v) {4Intent Intent =NewIntent (first. This, Second.class);5Startactivityforresult (intent,1);6 }7 });8 9 Ten @Override One protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { A Super. Onactivityresult (Requestcode, ResultCode, data); - if(Requestcode = = 1 && resultcode = 2){ -String a = Data.getstringextra ("AAA"); the Tv.settext (a); - } -----------------------Gorgeous de line----------------------- -Bt2.setonclicklistener (NewView.onclicklistener () { + @Override - Public voidOnClick (View v) { +Intent Intent =NewIntent ();//callback Intent no parameters required. AString s=(String) Tv.gettext (); atIntent.putextra ("AAA", s);//add key, value to intent intent -Setresult (2, intent);//Set the return label, here is 2; The callback is intent . - -Finish ();//destroying the current page - } -});
1.startActivityForResult (Intent,requestcode), with return value
The first parameter is a intent object
The second parameter is an identity of the request, which is the request label
2. The method of receiving return data via Startactivityforresult jump
Onactivityresult (int requestcode,int resultcode,intentdata)
The first parameter is the identity of the request
The second parameter is the identity returned by the second page
The third parameter is the data returned from the second page
3.setResult (Resultcode,data)
Uploading to the first page is actually a intent object
Intent data=new Intent ();
Data.putextra ("Data", content);
Setresut (2,data);
Finish ();//End Current page
Activity's jump and return value, Activity's life cycle