Several ways that Android activity jumps

Source: Internet
Author: User

This article is reproduced in http://blog.sina.com.cn/s/blog_5140274d0100q4j7.html, I only as a learning exchange, please respect the original.

the first way, use action to jump.  1, use the action jump, if there is a program in the androidmanifest.xml of an activity in the Intentfilter segment defined contains the same action then this intent Match with this target action. If type,category is not defined in this intentfilter segment, then the activity is matched. But if you have more than two programs in your phone, a dialog box will pop up to show you the message. The value of action has a lot of pre-defined in Android, and if you want to go directly to your own defined intent receiver, you can add a custom action value to the recipient's Intentfilter (and set the category value to " Android.intent.category.DEFAULT "), set the Action in your intent to intent, and you can jump directly to your own intent receiver. Because this action is unique in the system.  2,data/type, you can use URIs as data, such as URI uri = Uri.parse (http://www.google.com); Intent i = new Intent (intent.action_ View,uri), the intent distribution process of the mobile phone, according to Http://www.google.com scheme to determine the data type of the phone's brower can match it, In the intenfilter of Brower manifest.xml, there is the first Action_view Action, which can also handle the type of http:.  3, as for classification category, generally do not go to set it in intent, if you write intent receiver, in the manifest.xml activity The intentfilter contains Android.category.DEFAULT so that all Intent that do not set the category (Intent.addcategory (String c);) will match the category.  4,extras (additional information), is a collection of all other additional information. You can use extras to provide extended information for your component, such as, if you want to perform the "Send e-mail" action, you can save the e-mail message's title, body, and so on in extras, to the e-mail sending component.  java Code PackAge com.android.edit_text;  
Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;Importandroid.view.KeyEvent;ImportAndroid.view.View;ImportAndroid.widget.EditText;  Public classMyedittextextendsActivity {PrivateTextView M_textview;PrivateEditText M_edittext; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);         Setcontentview (R.layout.main); M_edittext= (EditText) This. Findviewbyid (r.id.edittext01); M_edittext.setonkeylistener (Edittextkeylistener); }  PrivateEdittext.onkeylistener Edittextkeylistener =NewEdittext.onkeylistener () {@Override Public BooleanOnKey (View arg0,intarg1, KeyEvent arg2) {                             //action Jump, you need to configure the action in Androidmanifest.xmlIntent i =NewIntent ("Android.intent.action.mydialog"); Myedittext. This. startactivity (i); return false; } }; } 

Copy Code XML code
<?XML version= "1.0" encoding= "Utf-8"?> <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.android.edit_text"Android:versioncode= "1"Android:versionname= "1.0"> <ApplicationAndroid:icon= "@drawable/icon"Android:label= "@string/app_name">        <ActivityAndroid:name=". Myedittext "Android:label= "@string/app_name">          <Intent-filter>             <ActionAndroid:name= "Android.intent.action.MAIN" />             <categoryAndroid:name= "Android.intent.category.LAUNCHER" />          </Intent-filter>        </Activity>             <!--Configure jump Activity -        <ActivityAndroid:name= "Com.android.dialog.MyDialog">          <Intent-filter> <!--Configure the action path -             <ActionAndroid:name= "Android.intent.action.mydialog" />             <categoryAndroid:name= "Android.intent.category.DEFAULT" />          </Intent-filter>        </Activity> </Application> <USES-SDKandroid:minsdkversion= "7" />  </Manifest> 

the second way, jump with the class name. Intent is responsible for the action of an operation in the application, the action involves data, the additional data is described, Android according to this intent description, is responsible to find the corresponding component, the intent passed to the calling component, and complete the call of the component. Intent is where the decoupling between the caller and the callee is implemented. In the intent delivery process, the target consumer (another activity,intentreceiver or service) is found, that is, the responder of intent. Java code Package COM. Android;
Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;  Public classFormstuffextendsActivity {@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);         Setcontentview (R.layout.formstuff); FinalImageButton button =(ImageButton) Findviewbyid (R.id.android_button); Button.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {//jump with class name, need to declare activity in Androidmanifest.xmlIntent Intent =NewIntent (Formstuff. This, Hellotabwidget.class);          StartActivity (Intent);  }        }); } 

XML code
<?XML version= "1.0" encoding= "Utf-8"?> <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "com. Android "Android:versioncode= "1"Android:versionname= "1.0">  <ApplicationAndroid:icon= "@drawable/icon"Android:theme= "@android: Style/theme.notitlebar">        <ActivityAndroid:name=". Formstuff "Android:label= "@string/app_name">          <Intent-filter>             <ActionAndroid:name= "Android.intent.action.MAIN" />             <categoryAndroid:name= "Android.intent.category.LAUNCHER" />          </Intent-filter>        </Activity>        <!--Affirm Activity - <ActivityAndroid:name= "Hellotabwidget"></Activity> </Application> <USES-SDKandroid:minsdkversion= "4" /> </Manifest> 

 Third Way: page jump via URI

Some common methods of intent:

The Java code displays the page  1. Uri uri = uri.parse ("http://google.com");  2. Intent it = new Intent (Intent.action_view, URI);  3. StartActivity (IT);   Show Map   1. Uri uri = uri.parse ("geo:38.899533,-77.036476");  2. Intent it = new Intent (Intent.action_view, URI);  3. StartActivity (it);  4. Other Geo URI example  5. Geo:latitude,longitude 6. Geo:latitude,longitude?z=zoom 7. Geo:0,0?q=my+street+address 8. Geo:0,0?q=business+near+city 9. Google.streetview:cbll=lat,lng&amp;cbp=1,yaw,,pitch,zoom&amp;mz=mapzoom      Path Planning   1. Uri uri = Uri.parse ("Http://maps.google.com/maps?f=d&amp;saddr=startLat Startlng&amp;daddr=endlat endlng &amp;hl=en ");  2. Intent it = new Intent (Intent.action_view, URI);  3. StartActivity (it);  4. Where Startlat, STARTLNG, Endlat, ENDLNG is a long with 6 decimals like:50.123456   call  1. Call out dialer   2. Uri uri = Uri.parse ("tel:0800000123 ");  3. Intent it = new Intent (intent.action_dial, URI);  4. StartActivity (it);   1. Just call out  2. Uri uri = uri.parse ("tel:0800000123");  3. Intent it = new Intent (Intent.action_call, URI);  4. StartActivity (it);  5. With this one, in the Androidmanifest.xml, add  6. &lt;uses-permission id= "Android.permission.CALL_PHONE"/&gt;    transmits sms/mms 1. Call SMS program &NBSP;&NBSP;2. Intent it = new Intent (Intent.action_view, URI);  3. It.putextra ("Sms_body", "The SMS Text");  4. It.settype ("vnd.android-dir/mms-sms");  5. StartActivity (IT);    1. Transmits message   2. Uri uri = uri.parse ("smsto://0800000123");  3. Intent it = new Intent (intent.action_sendto, URI);  4. It.putextra ("Sms_body", "The SMS Text");  5. StartActivity (IT);    1. Transfer mms 2. Uri uri = uri.parse ("Content://media/external/images/media/23");  3. Intent it = new Intent (intent.action_send);  4. It.putextra ("SMS_body "," some text ");  5. It.putextra (Intent.extra_stream, URI);  6. It.settype ("Image/png");  7. StartActivity (IT);   transfer email 1. Uri uri = Uri.parse ("mailto:x[email protected]");  2. Intent it = new Intent (intent.action_sendto, URI);  3. StartActivity (it);   1. Intent it = new Intent (intent.action_send);  2. It.putextra (Intent.extra_email, "[email protected]");  3. It.putextra (Intent.extra_text, "The email body TEXT");  4. It.settype ("Text/plain");  5. StartActivity (Intent.createchooser (it, "Choose Email Client"))   1. Intent it=new Intent (intent.action_send);   &NBSP;&NBSP;2. String[] tos={"[email protected]"};     3. String[] ccs={"[email protected]"};     4. It.putextra (Intent.extra_email, TOS);     5. It.putextra (INTENT.EXTRA_CC, CCS);     6. It.putextra (Intent.extra_text, "The email body TEXT");     7. It.putextRA (intent.extra_subject, "The email SUBJECT text");     8. It.settype ("message/rfc822");     9. StartActivity (Intent.createchooser (it, "Choose Email Client"));    1. Transfer Attachment  2. Intent it = new Intent (intent.action_send);  3. It.putextra (Intent.extra_subject, "The email SUBJECT text");  4. It.putextra (Intent.extra_stream, "File:///sdcard/mysong.mp3");  5. Sendintent.settype ("Audio/mp3");  6. StartActivity (Intent.createchooser (it, "Choose Email Client"));     play multimedia     uri uri = uri.parse ("File:///sdcard/song.mp3");    Intent it = new Intent (Intent.action_view, URI);    it.settype ("Audio/mp3");    startActivity (it);         uri uri = Uri.withappendedpath (MediaStore.Audio.Media.INTERNAL_CONTENT_ URI, "1");    Intent it = new Intent (Intent.action_view, URI);     startactivity (it );       market related  1.        //looking for an app   2.        uri Uri = Uri.parse ("Market://search?q=pname:pkg_name");   3.        intent it = new Intent (Intent.action_view, URI);  4.        startactivity (it);  5.        //where Pkg_name is the full package, path for an application    1.        //displays information about an app   2.        uri Uri = Uri.parse ("market://details?id=app_id");  3.        intent it = new Intent (Intent.action_view, URI);   4.        startactivity (it);  5.        //where app_id is the application ID, find the id 6.        //by Clicking on your application in market home 7.        //page, and notice the ID from the address bar      1.        uri Uri = uri.fromparts ("package", strpackagename, NULL);   2.        intent it = new Intent (Intent.action_delete, URI);  3.        startactivity (IT);  

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.