How does Android open another APP from an APP?

Source: Internet
Author: User

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 );


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.