Intent-Intent Action of Android robots from the ground up

Source: Internet
Author: User

 

Action attribute of Intetn:

What is Action?

Action is a String constant. In the Intent class, the constant attribute of the master's Action is defined, for example, ACTION_CALL (CALL) ACTION_EDIT (edit data). In addition, setAction () can be used () function to set the IntnetAction attribute and use getAction () to obtain the Action

1. Custom Action:

Let's look at the Intent constructor:

Public Intent ()

Default constructor

Public Intent (Intent o)

Copy it from a created Intent

Public Intent (String action)

Creates Intent using the specified action. Some common actions will be pointed out later.

Public Intent (String action, Uri uri)

Creates an Intent using the specified action and uri.

Public Intent (Context packageContext, Class <?> Cls)

Parameter description:

PackageContext: application context

Cls: The target component for receiving Intent

Public Intent (String action, Uri uri, Context packageContext, Class <?> Cls)

Parameter description:

Action: The specified action, for example, ACTION_VIEW.

PackageContext: application context

Cls: The target component for receiving Intent

Uri: the specified uri.

Start Activity

1. Display startup: the class of the started Activity must be specified.

// Create an Intent application context target component

Print?

Intent intent = new Intent (IntentDemo01Activity. this,

ActivityToStart. class );

// Display start Activity

StartActivity (intent );

 

Sample Code:

Print?

Package com. jiahui. activity;

 

Import android. app. Activity;

Import android. content. Intent;

Import android. OS. Bundle;

Import android. view. View;

Import android. view. View. OnClickListener;

Import android. widget. Button;

 

Public class IntentDemo01Activity extends Activity {

Private Button myBtn;

 

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

SetContentView (R. layout. main );

MyBtn = (Button) findViewById (R. id. myBtn );

MyBtn. setText ("START ActivtiToStart ");

MyBtn. setOnClickListener (new OnClickListener (){

Public void onClick (View v ){

// Create an Intent application context target component

Intent intent = new Intent (IntentDemo01Activity. this, ActivityToStart. class );

// Display start Activity

StartActivity (intent );

}

});

}

}

 

Print?

Package com. jiahui. activity;

 

Import android. app. Activity;

Import android. OS. Bundle;

Import android. widget. TextView;

Public class ActivityToStart extends Activity {

@ Override

Protected void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

SetContentView (R. layout. start );

TextView myText = (TextView) findViewById (R. id. startTxt );

 

MyText. setText ("started Activity ");

 

}

 

}

 

 

2. Implicit start: the Android system determines which Activity to start based on the Intent action and data, and only contains the action to be executed and the data contained. You do not need to specify the Activity.

Print?

Package com. jiahui. activity;

 

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;

Public class IntentDemo02Activity extends Activity {

Private Button myBtn;

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

SetContentView (R. layout. main );

MyBtn = (Button) findViewById (R. id. myBtn );

MyBtn. setText ("implicit ");

MyBtn. setOnClickListener (new OnClickListener (){

Public void onClick (View v ){

// Browse

// Intent intent = new Intent (Intent. ACTION_VIEW, Uri

//. Parse ("http://www.goole.com.cn "));

//

// Display the dial

Intent intent = new Intent (Intent. ACTION_DIAL );

StartActivity (intent );

}

});

}

}

Integrated instance 1:

Print?

Package com. jiahui. activity;

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 android. widget. EditText;

Public class IntentWebViewDemoActivity extends Activity {

Private Button myBtn;

Private EditText myText;

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

SetContentView (R. layout. main );

MyBtn = (Button) findViewById (R. id. myBtn );

MyText = (EditText) findViewById (R. id. edtxt01 );

MyBtn. setText ("Browse ");

MyBtn. setOnClickListener (new OnClickListener (){

@ Override

Public void onClick (View v ){

String uriString = myText. getText (). toString ();

Intent intent = new Intent (Intent. ACTION_VIEW, Uri

. Parse (uriString ));

 

StartActivity (intent );

 

}

});

 

}

}

 

If you need to reprint reference please indicate the source: http://blog.csdn.net/jiahui524

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.