The most important way to pass a value between two apps is
Intent Intent = Getpackagemanager (). Getlaunchintentforpackage ("com.example.app2");
The other values are performed using intent similar to the value of the activity.
(You can also customize the activity's permissions)
APP1:
PackageCom.example.app1;Importandroid.content.Intent;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.Toast; Public classMainactivityextendsAppcompatactivityImplementsView.onclicklistener {PrivateButton btn1; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); BTN1=(Button) Findviewbyid (R.ID.BTN_APP1); Btn1.setonclicklistener ( This); } @Override Public voidOnClick (View v) {//get the app to jump through the package name, create the intent objectIntent Intent = Getpackagemanager (). Getlaunchintentforpackage ("Com.example.app2"); if(Intent! =NULL) { //Here's the same thing as the activity pass parameter, don't worry about how to pass the parameters, and the receiving parameters are the same as the activity and activity parameters.Intent.putextra ("Value", "I am APP1"); StartActivity (Intent); } Else{Toast.maketext (Getapplicationcontext (),"Not this app yet", Toast.length_short). Show (); } }}
Receive in APP2
Packagecom.example.app2;Importandroid.content.Intent;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.widget.TextView; Public classMainactivityextendsappcompatactivity {PrivateTextView TV2; PrivateIntent Intent; PrivateString value; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Intent=getintent (); Bundle Bundle=Intent.getextras (); if(Bundle! =NULL) {Value= Bundle.getstring ("Value"); }Else{Value= "No value received for APP1"; } TV2=(TextView) Findviewbyid (R.ID.TV2); Tv2.settext (value); }}
Jump and pass values between two apps