The concept and application of Intent in Android

Source: Internet
Author: User

first, the explicit type intent: startactivity (New Intent (Mainactivity.this, class name));  

Second, implicit intent:

1. Register <activity> tags in the <application> tab of the Androidmanifest.xml file, like the. Class name:  <activity android:name =". Another " android:exported=" false " >             <intent-filter >                 <action android:name= "Com.example.jikexueyuan_ Learnintent.intent.action.another "/>                 <category android:name= "Android.intent.category.DEFAULT"/>             </intent-filter>   </ activity>        NOTE: The exported property is the ability to reference or open this activity in other apps, that is, whether it can be exported         & nbsp     Intet-filter in the,<action> tag, give the activity a name, any (generally: package name. intent.action. Class name) <category> tags, is generally android.intent.category.DEFAULT. 2. In the called Class, StartActivity (New Intent (" ,<action> tag in Intet-filter, name of the activity"); Findviewbyid (R.id.btn_startanotheraty). Setonclicklistener (New Onclicklistener () {@Override Publ IC void OnClick (View v) {//TODO auto-generated method stub try { startactivity (New Intent ("Com.example.jikexueyuan_learnintent.intent.action.another"));} catch (Exception e) {//Todo:handle Exception Toast.maketext (mainactivity.this, "Unable to start", Toast.length_short). Show (); //Use of toast}}); 3. You can also directly define a class B that you want to open with another public static constant string Public static final String Action = "Com.example.jikexueyuan_learnintent.intent.action.another"; It is then easier to understand that when called, the activity name is changed to the class name b.action. namely: startactivity (New Intent (another.action));   Three,Intent filter related options: Create two new apps (APP1 and APP2) in one app and register <activity> tags in the <application> tab of the Androidmanifest.xml file, like the. class name; Intet-filter,<action> tag, give this; two activity takes the same name. The APP3 invokes the program startactivity (New Intent ("name")), and the result is as follows : You will be prompted to select the app to run (1 run once only 2 is set as default), if you set APP1 to defaultTo Cancel, just in Settings-"Application-" app1-"(default startup in application information) clear default settingsIn one of the apps (like APP1), add the data tag to the <application> <intent-filter > in the Androidmanifest.xml file. and define a protocol for the app: <data android:scheme= "app"/> (to see what other tags mean) go back to APP3 's calling program startactivity (New Intent ("name")); Add, uri.parse ("app://") field. That  startactivity (New Intent ("name", Uri.parse ("app://" )); (app://can be added to any field lake or not added later)

The concept and application of Intent in Android

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.