We can also use the hermit intent to activate the custom interface, and can carry data:
Effect:
After clicking the second button:
Attached code:
Code for the main form:
1 Packagecom.yy.twoactivity;2 3 Importandroid.app.Activity;4 Importandroid.content.Intent;5 ImportAndroid.net.Uri;6 ImportAndroid.os.Bundle;7 ImportAndroid.view.View;8 9 Public classMainactivityextendsActivity {Ten One @Override A protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); the } - - /** - * Click the event to jump to the second screen when the user clicks + * @paramView - */ + Public voidClick (View view) { A //Intentions atIntent intent=NewIntent (); - //set up packages and interfaces, explicit intent -Intent.setclassname ( This, "Com.yy.twoactivity.SecondActivity"); - //jump to the new set-up interface - startactivity (intent); - } in - /** to * Click the event, when the user clicks the implicit intention to jump to the second interface + * @paramView - */ the Public voidClick3 (view view) { * //Intentions $Intent intent=NewIntent ();Panax Notoginseng //set up packages and interfaces, implicit intent -Intent.setaction ("Com.yy.xxx"); the //set additional information "not required, corresponding to master profile" + intent.addcategory (intent.category_default); A //set data "not required, corresponds to master profile, can carry data" theIntent.setdata (Uri.parse ("Yy:adbc")); + //jump to the new set-up interface - startactivity (intent); $ } $ - /** - * Click events to activate the system's application interface the * @paramView - */Wuyi Public voidClick2 (view view) { the //Intentions -Intent intent=NewIntent (); Wu //set the pre-open System app's package and interface, explicit intent - //Cmp=com.android.gallery/com.android.camera.gallerypicker AboutIntent.setclassname ("Com.android.gallery", "Com.android.camera.GalleryPicker"); $ //jump to the new set-up interface - startactivity (intent); - } -}
The code for the second form:
1 Packagecom.yy.twoactivity;2 3 Importandroid.app.Activity;4 Importandroid.content.Intent;5 ImportAndroid.net.Uri;6 ImportAndroid.os.Bundle;7 8 Public classSecondactivityextendsActivity {9 @OverrideTen protected voidonCreate (Bundle savedinstancestate) { One Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.activity2); - - //gets the intent to open the current interface theIntent intent=getintent (); -Uri uri=Intent.getdata (); - //get to use Intent.setdata (Uri.parse ("Yy:adbc")) and carry data -String Data=Uri.getschemespecificpart (); + System.out.println (data); - } +}
In addition, you need to configure it in the Andoridmanifest.xml file:
1<Application2Android:allowbackup= "true"3android:icon= "@drawable/ic_launcher"4Android:label= "@string/app_name"5Android:theme= "@style/apptheme" >6<Activity7Android:name= ". Mainactivity "8Android:label= "@string/app_name" >9<intent-filter>Ten<action android:name= "Android.intent.action.MAIN"/> One A<category android:name= "Android.intent.category.LAUNCHER"/> -</intent-filter> -</activity> the<Activity -Android:name= ". Secondactivity " -Android:label= "@string/app_second_name" > -<intent-filter> +<action android:name= "Com.yy.xxx"/> -<category android:name= "Android.intent.category.DEFAULT" ></category> +<data android:scheme= "yy"/> A</intent-filter> at</activity> -</application>
Android implicitly intends to activate the custom interface