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:" + );}}