The transfer of data between different interfaces is a very common operation, and this kind of data is very simple to carry.
Effect:
After jump:
This is a simple example, but we passed the first name Zhang San to the second interface.
The accompanying code is as follows:
Main interface:
1 PackageCom.yy.activity.value;2 3 Importandroid.app.Activity;4 Importandroid.content.Intent;5 ImportAndroid.os.Bundle;6 Importandroid.text.TextUtils;7 ImportAndroid.view.View;8 ImportAndroid.widget.EditText;9 ImportAndroid.widget.Toast;Ten One Public classMainactivityextendsActivity { A PrivateEditText Et_name; - - @Override the protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -Et_name=(EditText) Findviewbyid (r.id.et_name); + } - + Public voidClick (View view) { A //get the name entered in the text box atString name=Et_name.gettext (). toString (). Trim (); - if(Textutils.isempty (name)) { -Toast.maketext ( This, "Please enter your name", Toast.length_long). Show (); - return; - } - //Intentions inIntent intent=NewIntent (); - //in the same application, so we use explicit intent toIntent.setclassname ( This, "Com.yy.activity.value.ResultActivity"); + //carry string data, note: Eight basic data types can be carried -Intent.putextra ("name", name); the //activating the interface * startactivity (intent); $ }Panax Notoginseng}
Result interface:
1 PackageCom.yy.activity.value;2 3 ImportJava.util.Random;4 5 Importandroid.app.Activity;6 ImportAndroid.os.Bundle;7 ImportAndroid.widget.ProgressBar;8 ImportAndroid.widget.TextView;9 Ten Public classResultactivityextendsActivity { One PrivateTextView TV_RP; A PrivateProgressBar PB; - @Override - protected voidonCreate (Bundle savedinstancestate) { the Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_result); -tv_rp=(TextView) Findviewbyid (R.ID.TV_RP); -pb=(ProgressBar) Findviewbyid (R.ID.PB); + //get the name you passed over -String name=getintent (). Getstringextra ("name"); + //randomly generated character A intrp=NewRandom (). Nextint (101); atTv_rp.settext (name+ ":" +RP); - //set the progress bar - pb.setprogress (RP); - } -}
Transfer of data between Android interfaces