Use of Anroid intent, use of Anroid intent
Common inten actions: MAIN_ACTION (main view), VIEW_ACTION (view), EDIT_ACTION (modify), PICK_ACTION, GET_CONTENT_ACTION (obtain content) DIAL_ACTION, CALL_ACTION, SENDTO_ACTION, ANSWER_ACTION, INSERT_ACTION, DELETE_ACTION, RUN_ACTION, LOGIN_ACTION, role, SYNC_ACTION, PICK_ACTIVITY_ACTION, WEB_SEARCH_ACTION, etc.
Operation data:
1. action and data
2. category (category): additional information about the executed action. For example, LAUNCHER_CATEGORY indicates that the receiver of Intent should appear as a top-level application in Launcher, while ALTERNATIVE_CATEGORY indicates that the current Intent is one of a series of optional actions that can be executed on the same piece of data.
3. type (data type), explicitly specifying the Intent data type (MIME ). Generally, the Intent data type can be determined based on the data itself. However, by setting this attribute, You can forcibly use the explicitly specified type instead of derivation.
4. component: Specifies the Class Name of the Intent's target component. Generally, Android searches for other attributes in Intent, such as action, data/type, and category, and finds a matched target component. However, if this attribute of component is specified, the component specified by component will be used directly without executing the above search process. After this attribute is specified, all other Intent attributes are optional.
5. extras (additional information) is a collection of all other additional information. You can use extras to provide extended information for components. For example, if you want to perform the "send email" action, you can save the email title and body in extras, send to the email sending component.
Demo:
Package com. example. homekey; import android. OS. bundle; import android. app. activity; import android. content. intent; import android. view. menu; import android. view. view; import android. view. view. onClickListener; import android. widget. button; public class MainActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); Button btnhome = (Button) findViewById (R. id. btnhome); btnhome. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View arg0) {// TODO Auto-generated method stub // Intent intent Intent = new Intent (); // sets the intent action intent. setAction (intent. ACTION_MAIN); // sets the category intent. addCategory (intent. CATEGORY_HOME); // execution intent startActivity (intent) ;}}) ;}@ Overridepublic boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}
Run: