How does Android open another APP from an APP?
As we all know, in an APP, The startactivity function is used to jump from one page to another.
Similarly, the redirection between applications is also true. There are three scenarios for direct jump of an application. To facilitate the description, I add two applications A and B. The requirement is to click A button from A to jump to B, at the same time, A must transmit data to B, and B can receive and process the data:
1. jump from A to B's main Activity. The Code is as follows:
Intent intent = new Intent (Intent. ACTION_MAIN); intent. addCategory (Intent. CATEGORY_LAUNCHER); ComponentName comp = new ComponentName ("com. nbg. baby "," com. nbg. baby. mainActivity "); intent. setComponent (comp); int launchFlags = Intent. FLAG_ACTIVITY_NEW_TASK | Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED; intent. setFlags (launchFlags); intent. setAction ("android. intent. action. VIEW "); Bundle bundle = new Bundle (); bundle. putString ("from", "from test application"); intent. putExtras (bundle); startActivity (intent );
1.1 If application B is disabled, add the following statement to the onCreate () function:
Bundle bundle = this.getIntent().getExtras(); if(bundle!=null && bundle.getString("from")!=null){ Util.showToast(s_instance, bundle.getString("from"), Toast.LENGTH_LONG); }
1.2 If application B is enabled, add the following statement to the onRestart () function:
Bundle bundle = this.getIntent().getExtras(); if(bundle!=null && bundle.getString("from")!=null){ Util.showToast(s_instance, bundle.getString("from"), Toast.LENGTH_LONG); }
2. A activity set to exported jumped from A to B. The status of application B does not matter. The Code is as follows:
ComponentName comp = new ComponentName ("com. nbg. baby "," com. nbg. baby. apiLoginActivity "); Intent intent = new Intent (); intent. setComponent (comp); intent. setAction (Intent. ACTION_VIEW); Bundle bundle = new Bundle (); bundle. putString ("extra", "I am from the stars"); intent. putExtras (bundle); context. startActivityForResult (intent, 1 );