Android--activity and Intent

Source: Internet
Author: User

one, about intent


first look at what a intent contains:

1 , Com ponent Name : decide which component to start

2,action : Activity What actions should be done

3,data: a Activity to a different Activity the data passed

4,category:

5,extras: Key-value pairs

6,flags


compared with the HttpRequest in. NET, it feels quite like, it's a good coincidence.



Two, start another activity in one activity


First we create two activity, add a button to the activity entered at startup, click this button, and then jump to another activity.


Package Com.example.activity_02;import Android.net.uri;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 {private Button mybutton=null;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);  Sets the XML mybutton= (Button) Findviewbyid (R.id.mybutton) used by the current layout;  Gets the button Mybutton.setonclicklistener (new Mybuttonlisterner ()) on the activity;        Bind the Mybuttonlisterner to mybutton above to achieve a click when jumping} @Override public 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; } class Mybuttonlisterner implements onclicklistener{@Override public void OnClick (View arg0) {//TODO auto-generated method stub//Generate a Intent object Intent intent=new Intent (); Intent.putextra ("Textintent", "PBC");//Put key-value pairs in intent to pass Intent.setclass (Mainactivity.this,otheractivity.class) ; Set to jump from current activity to otheractivity MainActivity.this.startActivity (intent);//Start additional activity/*uri uri=uri.parse ("Smst  O://0800000123 ");  Intent intent=new Intent (Intent.action_sendto,uri);  Intent.putextra ("The SMS Body", "the SMS Text");     StartActivity (Intent), */}}}



First we need to add a similar event listener on the button to do some jump processing when clicked. Later, in this specific process, we use the intent object to implement the pass-through value, which is set to jump from the current activity to that activity. You can also use intent to invoke the functionality of the system.



Summary:

For example, in BS or CS, page form transfer values are essential things, to the Android development here, and there are such things, so according to the previous things to learn, and by analogy, you can compare the basic knowledge of what Android needs.







Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android--activity and Intent

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.