Implicit intent, intent

Source: Internet
Author: User

Implicit intent, intent
Implicit intent

1. Introduction to implicit intent

 

Explicit intent we mentioned earlier, such:

Intent intent = new Intent ();

Intent. setClass (this, Other. class); // this sentence indicates an explicit intent, because it explicitly sets the activation object to an Other class.

StartActivity (intent );

 

As the name implies, the implicit intention is to find the most matched component without explicitly setting the activation object. For example, five people:

(1) A: 170

(2) B: 160

3) C: 180

(4) D: 190

(5) E: 200

If it is explicit, if we want to specify A, it will say, "I chose. ", but if it is an implicit intention, it will say:" I want to select 170cm people ". Although it does not specify to select A, it will find the person with the most matching conditions.

 

In the intent filter, matching conditions similar to the "height" condition in the preceding example include:

(1) action

(2) category

(3) data: scheme, host, path, type

When the conditions for activating components are set in the program, the program will look for the most matched components, but note: as long as there is a bit of mismatch, it will not match;

For example:

Intent intent = new Intent ();

Intent. setAction ("a"); // This sentence only specifies the Action

StartActivity (intent); // find the most matched component for activation. intent. addCategory ("Android. intent. category. DEFAULT") is called internally ");

 

Reference: http://blog.csdn.net/xiazdong/article/details/7764865

 

Ii. code example

Com. example. implicit2a_Intent.MainActivity

Package com. example. implicit2a_Intent; import com. example. implicit2_intent.R; import android. app. activity; import android. content. dialogInterface; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button; public class MainActivity extends Activity implements OnClickListener {private Button btn_one; @ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); btn_one = (Button) findViewById (R. id. button1); btn_one.setOnClickListener (this) ;}@ Override public void onClick (View v) {// TODO Auto-generated method stub Intent intent = new Intent (); /*** find all actions that match "com. fry. activity01 "page * also finds all Category android. intent. category. DEFAULT Page * String android. content. intent. CATEGORY_DEFAULT = * "android. intent. category. DEFAULT "*/intent. setAction ("com. fry. activity01 "); intent. addCategory (Intent. CATEGORY_DEFAULT); startActivity (intent );}}

/Implicit2_Intent/AndroidManifest. xml

 1 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2     package="com.example.implicit2_intent" 3     android:versionCode="1" 4     android:versionName="1.0" > 5  6     <uses-sdk 7         android:minSdkVersion="8" 8         android:targetSdkVersion="19" /> 9 10     <application11         android:allowBackup="true"12         android:icon="@drawable/ic_launcher"13         android:label="@string/app_name"14         android:theme="@style/AppTheme" >15         <activity16             android:name="com.example.implicit2a_Intent.MainActivity"17             android:label="@string/app_name" >18             <intent-filter>19                 <action android:name="android.intent.action.MAIN" />20 21                 <category android:name="android.intent.category.LAUNCHER" />22             </intent-filter>23         </activity>24         <activity android:name="com.example.implicit2a_Intent.Activity03">25             <intent-filter >26                 <action android:name="com.fry.activity01"></action>27                 <category android:name="android.intent.category.DEFAULT"/>28             </intent-filter>29         </activity>30     </application>31 32 </manifest>

Another Application

Com. example. implicit1Intent. MainActivity

1 package com. example. implicit1Intent; 2 3 4 import com. example. implicitintent. r; 5 6 import android. app. activity; 7 import android. content. dialogInterface; 8 import android. content. intent; 9 import android. OS. bundle; 10 import android. view. view; 11 import android. view. view. onClickListener; 12 import android. widget. button; 13 14 public class MainActivity extends Activity implements OnClickListener {15 private Button btn_one; 16 @ Override17 protected void onCreate (Bundle savedInstanceState) {18 // TODO Auto-generated method stub19 super. onCreate (savedInstanceState); 20 setContentView (R. layout. activity_main); 21 btn_one = (Button) findViewById (R. id. button1); 22 btn_one.setOnClickListener (this); 23} 24 @ Override25 public void onClick (View v) {26 // TODO Auto-generated method stub27 Intent intent = new Intent (); 28/** 29 * Find all actions as "com. fry. activity01 "page 30 * also finds that all Category is android. intent. category. DEFAULT Page 31 * String android. content. intent. CATEGORY_DEFAULT = 32 * "android. intent. category. DEFAULT "33 */34 intent. setAction ("com. fry. activity01 "); 35 intent. addCategory (Intent. CATEGORY_DEFAULT); 36 startActivity (intent); 37} 38 39 40}

/Implicit_Intent/AndroidManifest. xml

 1 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 2     package="com.example.implicitintent" 3     android:versionCode="1" 4     android:versionName="1.0" > 5  6     <uses-sdk 7         android:minSdkVersion="8" 8         android:targetSdkVersion="19" /> 9 10     <application11         android:allowBackup="true"12         android:icon="@drawable/ic_launcher"13         android:label="@string/app_name"14         android:theme="@style/AppTheme" >15         <activity16             android:name="com.example.implicit1Intent.MainActivity"17             android:label="@string/app_name" >18             <intent-filter>19                 <action android:name="android.intent.action.MAIN" />20 21                 <category android:name="android.intent.category.LAUNCHER" />22             </intent-filter>23         </activity>24         <activity android:name="com.example.implicit1Intent.Activity01">25             <intent-filter >26                 <action android:name="com.fry.activity01"></action>27                 <category android:name="android.intent.category.DEFAULT"/>28             </intent-filter>29         </activity>30         <activity android:name="com.example.implicit1Intent.Activity02">31             <intent-filter >32                 <action android:name="com.fry.activity01"></action>33                 <category android:name="android.intent.category.DEFAULT"/>34             </intent-filter>35         </activity>36     </application>37 38 </manifest>

 

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.