Activity switching
Two different ways
>1. Direct Jump
New Intent (mainactivity. this, secondactivity. class ); startactivity (intent);
>> need to carry parameters is required to use
Intent.putextra ("Key", "value");
>> target activity take parameter use
Getintent (). Getstringextra ("key")
>2. Jump with return value
New Intent (mainactivity. this, secondactivity. class ); Intent.putextra ("key"1);
>> target Activity returns
New Intent (); Intent.putextra ("code", "OK"), Setresult ((int)Requestcode, Intent); Finish ();
>>>finish () function: Execution finishes destroying this activity, this activityresult returns to the caller and calls the Onactivityresult () function.
>> original activity accept the return value operation
@Override protectedvoid onactivityresult (intint ResultCode, Intent data) { super. Onactivityresult (Requestcode, ResultCode, data); Determine the operation if (requestcode==1 && resultcode==2) {medittext.settext ( Data.getstringextra ("code")); // Toast.maketext (Mainactivity.this, Data.getstringextra ("code"), Toast.length_long). Show (); } }
Android Intent Learning Notes