Android intent implicitly invokes one application to launch another application (reprinted)

Source: Internet
Author: User

One of the keys to understanding intent is to understand the two basic usages of intent: an explicit intent that designates the receiver when constructing the intent object, similar to a normal function call, and an implicit intent, That is, when the sender of the intent constructs the intent object, it does not know or care who the receiver is, which is quite different from the function call, which helps to reduce the coupling between sender and receiver. In addition, intent can also be used for broadcasting in addition to sending.

Display call 1.Intent Intent = new Intent (); Intent.setclass (A.this,b.class); Intent.setclassname ("Com.view", "com.view.b"); The former is the package name of a, the latter is the class name of the B

StartActivity (Intent);

Implicit invocation: private static String my_action = "Com.view.my_action";

Intent Intent = new Intent (); Intent.setaction (my_action);

or//Intent Intent = new Intent (my_action);

StartActivity (Intent);

Implicit invocation is not only declared in the Androidmanifest.xml file, but also added Intent-filter

In the activity of Class B, add:

<intent-filter>

<action android:name= "Com.view.my_action"/> <!--customization

</intent-filter>

With this sentence, you can jump to class B.

If you want to start another application, such as Class B is at the entrance of another application, add another intent-filter to its activity

<activity android:name= ". B "android:label=" @string/app_name ">

<intent-filter>

<action android:name= "Android.intent.action.MAIN"/>

<category android:name= "Android.intent.category.LAUNCHER"/>

</intent-filter>

<intent-filter>

<action android:name= "Com.view.my_action"/>

<action android:name= "Android.intent.action.DEFAULT"/>

<category android:name= "Android.intent.category.DEFAULT"/>

</intent-filter>

</activity>

Android intent implicitly invokes one application to launch another application (reprinted)

Related Article

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.