Android development-implicit intent

Source: Internet
Author: User

The implicit intent is to indicate that the primary key name needs to be displayed, but by specifying action, data, category, the Android system finds and activates the most suitable components based on these three features. First look at the custom example [html] <application android: icon = "@ drawable/icon" android: label = "@ string/app_name"> <activity android: name = ". mainActivity "android: label =" @ string/app_name "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> <activity android: name = ". otherActivity1 "android: label =" @ string/app_name "> <intent-filter> <action android: name =" cn. xy. action "/> <category android: name =" android. intent. category. DEFAULT "> </category> </intent-filter> </activity> <activity android: name = ". otherActivity2 "android: label =" @ string/app_name "> <intent-filter> <action android: name =" cn. xy. action2 "/> <action android: name =" cn. xy2.action2 "/> <category android: name =" cn. xy. category2 "> </category> <category android: name =" cn. xy2.category2 "> </category> <category android: name =" android. intent. category. DEFAULT "> </category> </intent-filter> </activity> <activity android: name = ". otherActivity3 "android: label =" @ string/app_name "> <intent-filter> <action android: name =" cn. xy. action3 "/> <category android: name =" cn. xy. category3 "> </category> <data android: scheme =" xy "android: host =" www.xy.cn "android: path ="/xy "> </data> <category android: name = "android. intent. category. DEFAULT "> </category> </intent-filter> </activity> <activity android: name = ". otherActivity4 "android: label =" @ string/app_name "> <intent-filter> <action android: name =" cn. xy. action4 "/> <category android: name =" cn. xy. category4 "> </category> <data android: scheme =" xy "android: host =" www.xy.cn "> </data> <data android: mimeType = "image/*"/> <category android: name = "android. intent. category. DEFAULT "> </category> </intent-filter> </activity> </application> <application android: icon =" @ drawable/icon "android: label = "@ string/app_name"> <activity android: name = ". mainActivity "android: label =" @ string/app_name "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> <activity android: name = ". otherActivity1 "android: label =" @ string/app_name "> <intent-filter> <action android: name =" cn. xy. action "/> <category android: name =" android. intent. category. DEFAULT "> </category> </intent-filter> </activity> <activity android: name = ". otherActivity2 "android: label =" @ string/app_name "> <intent-filter> <action android: name =" cn. xy. action2 "/> <action android: name =" cn. xy2.action2 "/> <category android: name =" cn. xy. category2 "> </category> <category android: name =" cn. xy2.category2 "> </category> <category android: name =" android. intent. category. DEFAULT "> </category> </intent-filter> </activity> <activity android: name = ". otherActivity3 "android: label =" @ string/app_name "> <intent-filter> <action android: name =" cn. xy. action3 "/> <category android: name =" cn. xy. category3 "> </category> <data android: scheme =" xy "android: host =" www.xy.cn "android: path ="/xy "> </data> <category android: name = "android. intent. category. DEFAULT "> </category> </intent-filter> </activity> <activity android: name = ". otherActivity4 "android: label =" @ string/app_name "> <intent-filter> <action android: name =" cn. xy. action4 "/> <category android: name =" cn. xy. category4 "> </category> <data android: scheme =" xy "android: host =" www.xy.cn "> </data> <data android: mimeType = "image/*"/> <category android: name = "android. intent. category. DEFAULT "> </category> </intent-filter> </activity> </application> [java]/*** implicit intention to activate Activity ** @ author Xu Yue **/ public class MainActivity extends Activity {@ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main);} public void goActivity1 (View v) {Intent intent = new Intent (); intent. setAction ("cn. xy. action "); // The method registers android for intent by default. intent. category. DEFAULT category, so in AndroidManifest. enter this category in xml. startActivity (intent);} public void goActivity2 (View v) {// when only action and category are configured, as long as the action and category of intent appear in intent-filter, Intent intent = new Intent (); intent. setAction ("cn. xy. action2 "); intent. addCategory ("cn. xy. category2 "); this. startActivity (intent);} public void goActivity3 (View v) {Intent intent = new Intent (); intent. setAction ("cn. xy. action3 "); intent. addCategory ("cn. xy. category3 "); // The data is transmitted in the uri format. setData (Uri. parse ("xy: // www.xy.cn/xy"); this. startActivity (intent);} public void goActivity4 (View v) {Intent intent = new Intent (); intent. setAction ("cn. xy. action4 "); intent. addCategory ("cn. xy. category4 "); // setData and setType cannot be written separately, because setType will clear the intent value set by setData. setDataAndType (Uri. parse ("xy: // www.xy.cn/xxx"), "image/gif"); this. startActivity (intent) ;}}/*** implicit intention to activate Activity ** @ author Xu Yue **/public class MainActivity extends Activity {@ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main);} public void goActivity1 (View v) {Intent intent = new Intent (); intent. setAction ("cn. xy. action "); // The method registers android for intent by default. intent. category. DEFAULT category, so in AndroidManifest. enter this category in xml. startActivity (intent);} public void goActivity2 (View v) {// when only action and category are configured, as long as the action and category of intent appear in intent-filter, Intent intent = new Intent (); intent. setAction ("cn. xy. action2 "); intent. addCategory ("cn. xy. category2 "); this. startActivity (intent);} public void goActivity3 (View v) {Intent intent = new Intent (); intent. setAction ("cn. xy. action3 "); intent. addCategory ("cn. xy. category3 "); // The data is transmitted in the uri format. setData (Uri. parse ("xy: // www.xy.cn/xy"); this. startActivity (intent);} public void goActivity4 (View v) {Intent intent = new Intent (); intent. setAction ("cn. xy. action4 "); intent. addCategory ("cn. xy. category4 "); // setData and setType cannot be written separately, because setType will clear the intent value set by setData. setDataAndType (Uri. parse ("xy: // www.xy.cn/xxx"), "image/gif"); this. startActivity (intent) ;}} to see an example of a system intent, in the application, for example, to implement the call function [java] // v is the currently clicked Button Object public void onClick (View v) {// obtain the phone number String phone = txtPhone. getText (). toString (); // call the system's built-in dialer to set the dial Intent object intent Intent = new intent (); Intent. setAction ("android. intent. action. CALL "); intent. setData (Uri. parse ("tel:" + phone); // activate the Intent. The category android is automatically added to the Intent. intent. category. DEFAULT startActivity (intent );

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.