One, Android One application launched another application when there are 2 methods.
The first is to know the specific action,category of the app being invoked (typically the first two values are the default, that is, the following method), the package name and the class name
public void Start (View v) { Intent intent2 = new Intent ("Android.intent.action.MAIN"); Intent2.addcategory ("Android.intent.category.LAUNCHER"); ComponentName cn = New ComponentName ("Com.example.secondapp", "com.example.secondapp.MainActivity"); Intent2.setcomponent (CN);
Intent2.putextra ("name", "ZP"); This.startactivity (Intent2); }
The second way is to only know the application's package name, this way with more
public void Start2 (View v) { Packagemanager p=this.getpackagemanager (); Intent in= P.getlaunchintentforpackage ("Com.example.secondapp"), if (in!=null) {In.putextra ("name", "ZP"); This.startactivity ( in);} Else{toast.maketext (This, "Yo, hurry to download and install this app", Toast.length_long). Show ();} }
Second, in the start of the secondary program, you can pass the parameters, that is, using intent Putextra () value, or bulk with bundles, such as the transfer of "a startup application" see http://www.2cto.com/kf/201409/332952.html
Can be Intent.putextra first ("name", "ZP");Again startactivity (Intent) uses the following code in the launched application: You can get the data.
public class Mainactivity extends actionbaractivity {private TextView ed; @Override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Ed= (TextView) Findviewbyid (R.ID.TX); Intent Intent =getintent (); Bundle bundle = Intent.getextras (); if (bundle! = null) { string name= (String) bundle.get ("name"); Ed.settext (name); } }
One application in Android launches another application and passes the data.