Android Learning Path (iv) the use of implicit intent

Source: Internet
Author: User
the use of implicit intent

Write about the use of explicit intent in the previous article, this time, write about the use of implicit intent.

So what is implicit intent.

Definition: Implicit intent is a intent that does not have an explicit target component name.

So what's the effect of implicit intent?

In the display intent, the main is used for the program itself activity, Service, broadcaster communication between. Implicit intent is primarily used for communication between programs and other different applications.

Let me give you an example:

We know that a lot of mobile games in the play will have to share this function, click to share, it will appear, such as sent to QQ, what what micro-blog. This is actually the use of the implicit intent function.

This time I wrote a small program, is this, in the current program in the main activity in a button, click on the button to trigger the implicit intent event, and then. There is another activity in the current program, with only one textview in the activity, and one activity in the other, as well as a textview. Then, when I click on it, there will be something similar to what happens when you click and share in a hand swim. Take a look at the screenshot below:

Here on the road to Android Learning _3 and Andrew _4 are two different applications, the current program name is called the Android Learning Path _4, then click the first, the following will occur:

As shown in the figure above, the text appears in the activity in this application. When you click on the other one, the following will occur:

As shown in the figure above, clicking on the second one will show the activity in this program.

So how to achieve this function.

Take a look at this code:

public void OnClick (View v) {
		Intent Intent = new Intent ();
		Intent.setaction ("com.android_4.Activity");
		Intent.addcategory ("Android.intent.category.DEFAULT");
		Intent.addcategory (Intent.category_default);
		StartActivity (intent);
	}

This is the Click event for the button in the program. What's inside is not to speak first, look at the following:

It says, "jump to the activity in different programs, and not much in the activity class." Look at the Androidmanifest.xml in the two program, then we have to jump to the two activity, then definitely configure the activity in this XML file, let's take a look at the code:

<activity android:name= "com.example.android_3.Activity03" >
            <intent-filter >
                <action Android:name= "com.android.Activity"/>
                
                <category android:name= "Android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

This is the XML configuration in the Android learning Path _3.

<activity android:name= "Com.example.android_4.Activity01" >
            <intent-filter>
                <action Android:name= "com.android.Activity"/>
                
                <category android:name= "Android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

This is the XML configuration in the Android learning Path _4.

As you can see, the android:name in this action is the same, and it's the same as the setaction parameter in the mouse click time above, and now for Setaction, this method, An activity that uses the parameters to find the same name. Android.intent.category.DEFAULT This parameter is necessary for implicit intent.

Intent.addcategory (Intent.category_default);

This piece of code is to set the intent properties, where Intent.category_default is the above Android.intent.category.DEFAULT this, the two are equivalent. In fact, this piece of code is additive, because the default property of intent is this.

After you have done this, you will be able to share the functions like hand-swimming. Although a bit rough, but the basic functions are similar.

end~





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.