We know that the Intent application can start another Activity. Can we start another application? The answer is yes.
1. First, we create an Android app named AnotherPro, which has no content and is used to open another app.
2. Create a project to open the above application. The program interface is as follows:
3. modify the program code and add the following code in onCreate
anotherPro = (Button) findViewById(R.id.startAnotherPro);calendar = (Button) findViewById(R.id.startCalendar);anotherPro.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();intent.setComponent(new ComponentName("com.anotherpro", "com.anotherpro.MainActivity"));startActivity(intent);}});calendar.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));startActivity(intent);}});
Intent. setComponent (newComponentName(PackageName, mainActivityName); // The first parameter is the application package name, and the second parameter is the Activity started by the program.
Run the program. Click AnotherPro to open the first application;
Click Calendar to open the Calendar application of the system.