Android Anonymous start Activity start system activity

Source: Internet
Author: User

We generally know the name of the activity that needs to jump when we use intent for activity jumps, for example:

Intent intent=new Intent (firstactivity.this,secondactitivy.class); startactivity (Intent);
WhenSecondactitivy.classand firstactivity no longer the same app, we need to use the anonymous boot,

Anonymous boot:

You first need to set the XML configuration file for the secondactivity that is started:

   <activity android:name= "Testintent.secondactitivy" >            <intent-filter>                <action android:name= "Tosecondpage"/>                <category android:name= "Android.intent.category.DEFAULT"/>            </intent-filter >        </activity>
Firstactivity can use<action android:name= "Tosecondpage"/>

To find secondactivity.

The firstactivity code is as follows:

<span style= "White-space:pre" ></span>intent intent=new Intent (); Intent.setaction ("ToSecondPage"); StartActivity (Intent);


This allows you to use ActionName to transfer activity to a non-app


Starting the system activity is also implemented as follows:

A system-provided actionname to jump to the activity of the system while appending some messages; (XML is 4 simple buttons)

Package Testintent;import Java.net.url;import Android.app.activity;import android.content.intent;import Android.net.uri;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Com.example.androidtest.r;public class Firstactivity extends Activity implements Onclicklistener{private button towebbutton;private button topicbutton;private button tomesbutton;private button Tophonebutton; @Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview (R.layout.first_activity_main); toWeBButton= (Button) Findviewbyid (R.id.toweb); topicbutton= (Button) Findviewbyid (r.id.topic); tomesbutton= (button) Findviewbyid ( R.id.tomes); tophonebutton= (Button) Findviewbyid (R.id.tophone); Towebbutton.setonclicklistener (this); Topicbutton.setonclicklistener (This), Tomesbutton.setonclicklistener (this); Tophonebutton.setonclicklistener ( this);} @Overridepublic void OnClick (VieW v) {//TODO auto-generated method Stubintent intent=new Intent (); if (V.equals (Towebbutton)) {//Jump to Web page Baidu Home Intent.setaction (Intent.action_view); Uri Uri=uri.parse ("http://www.baidu.com"); Intent.setdata (URI);} else if (v.equals (Topicbutton)) {//Open system Picture intent.setaction (Intent.action_get_content); Intent.settype ("image/*");// Open all the pictures, if need to get the picture need write callback function}else if (v.equals (Tomesbutton)) {//Send message intent.setaction (intent.action_send); Intent.settype ("Text/plain"); Intent.putextra (Intent.extra_text, "This is the first time I've sent this message");} else if (v.equals (Tophonebutton)) {//Call intent.setaction (Intent.action_view); Uri Uri=uri.parse ("tel:1839860592"); Intent.setdata (URI);} StartActivity (intent);}}



Android Anonymous start Activity start system activity

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.