Intent, Intent

Source: Internet
Author: User

Intent, Intent
Intent

Intention

Intent's role in Android:
1. Activate system components, such as startActivity (Intent) and startService (Intent)
2. Transfer Data between system components

Log

Username: Lily gender: Female email: lily@qq.com

Chestnuts

Data transfer between two activities, jump from MainActivity to SecondActivity, and pass data

Activity_main

     
      
       
        
             
       
        
       
      
         
         
      
       
      
     
    
   
  
 

MainActivity

Public class MainActivity extends Activity implements View. onClickListener {private EditText etUserName; private RadioButton rbGenderMale; private EditText etAge; private Button btnSubmit; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); etUserName = (EditText) findViewById (R. id. et_username); rbGenderMale = (RadioButton) findViewById (R. id. rb_male); etAge = (EditText) findViewById (R. id. et_age); btnSubmit = (Button) findViewById (R. id. btn_submit); btnSubmit. setOnClickListener (this) ;}@ Override public void onClick (View v) {String username = etUserName. getText (). toString (). trim (); String gender = rbGenderMale. isChecked ()? "Male": "female"; int age = Integer. parseInt (etAge. getText (). toString (); Intent intent = new Intent (this, SecondActivity. class); intent. putExtra ("_ username", username); intent. putExtra ("_ gender", gender); intent. putExtra ("_ age", age); startActivity (intent );}}

SecondActivity

Public class SecondActivity extends Activity {private Button btnStart; private Button btnStop; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_second); Intent intent = getIntent (); String u = intent. getStringExtra ("_ username"); String g = intent. getStringExtra ("_ gender"); int a = intent. getIntExtra ("_ age", 0); Log. d ("Intent", "Name:" + u + "Gender:" + g + "Age:" + );}}

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.