Android starts the activity anonymously and starts the system activity

Source: Internet
Author: User

Android starts the activity anonymously and starts the system activity

Generally, when we use Intent for activity jump, we all know the name of the activity to jump to, for example:

 

Intent intent=new Intent(FirstActivity.this,SecondActitivy.class);startActivity(intent);
When SecondActitivy. class and FirstActivity are no longer the same App, we need to use anonymous startup,

 

Start anonymously:

First, you need to set the xml configuration file of the started SecondActivity:

 

               
                                 
              
  
         
FirstActivity can be used

 

To find SecondActivity

The FirstActivity code is as follows:

 

Intent intent=new Intent();intent.setAction("toSecondPage");startActivity(intent);

 

 

In this way, you can adjust the ActionName to an Activity that is not in the App.

 

The system activity is also started as follows:

The ActionName provided by a system is used to jump to the system Activity, and some messages can be appended. (xml is four 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 the Baidu homepage intent. setAction (Intent. ACTION_VIEW); Uri uri = Uri. parse ("http://www.baidu.com"); intent. setData (uri);} else if (v. equals (toPicButton) {// open the system image intent. setAction (Intent. ACTION_GET_CONTENT); intent. setType ("image/*"); // open all the images. if you need to obtain the image, you need to write the callback function} else if (v. equals (toMesButton) {// sends the message intent. setAction (Intent. ACTION_SEND); intent. setType ("text/plain"); intent. putExtra (Intent. EXTRA_TEXT, "this is my first message like this");} else if (v. equals (toPhoneButton) {// call intent. setAction (Intent. ACTION_VIEW); Uri uri = Uri. parse ("tel: 1839860592"); intent. setData (uri) ;}startactivity (intent );}}


 

 

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.