One, simple activities between the jump
BTN1 = (Button) Findviewbyid (R.ID.FIRST_BTN1); Btn1.setonclicklistener (new View.onclicklistener () { @Override public void OnClick (View v) { new Intent (firstactivity. this, Secondactivit. class ); StartActivity (intent); } });
explicit jump -jumps from firstactivity to secondactivity, and does not pass any other information.
Second, the implicit action mode jump
Add an action condition to the destination activity my.action,category setting to Default
... <activity android:name= ". Secondactivit "> <intent-filter> <action android:name="my.action"/> < Category android:name= "Android.intent.category.DEFAULT"/> </intent-filter> </activity> ...
Set the action in the source activity that intent jumps to the desired response, which must match the action set in the destination activity.
BTN1 = (Button) Findviewbyid (R.ID.FIRST_BTN1); Btn1.setonclicklistener (new View.onclicklistener () { @Override public void OnClick (View v) { new Intent ("my.action"); StartActivity (intent); } });
Iii. transfer of data when jumping between activities
The interface functions provided by intent are putextra as key values, and the source activity code is as follows:
BTN1 = (Button) Findviewbyid (R.ID.FIRST_BTN1); Btn1.setonclicklistener (new View.onclicklistener () { @Override public void OnClick (View v) { new Intent ("my.action"); Intent.putextra ("mytag", "myvalue"); StartActivity (intent); } });
At this time, the destination activity can get the data passed through the received intent, it is necessary to ensure that the key value is correct.
@Override protectedvoid onCreate (Bundle savedinstancestate) { Super . OnCreate (savedinstancestate); Setcontentview (R.layout.activity_second); = getintent (); = Intent.getstringextra ("mytag"); Toast.maketext (this, Str,toast.length_short). Show (); }
Android Learning with 2 (intent implementation activity jump)