Transferred from: http://www.cnblogs.com/leipei2352/archive/2011/08/09/2132096.html
Each activity in Android typically describes all the screens on a screen (except for window-level activity), so switching between the two interface (which is exactly the whole screen) of the phone screen involves switching between the activity.
Assuming there are two activity, Activity01 and Activity02, there is now a button on the ACTIVITY01 page that switches to Activity02 after the click. And when the activity switches, Activity01 passed a parameter to Activity02. (Intent can be used when switching activity and can pass data.)
How do you do it? The general idea is:
1. Set a trigger space in Activity01 and add a trigger
2. Add listener to the ACTIVITY01 trigger
3. In the Listener interface implementation, set up a intent that allows the intent to bind Activity01 and Activity02 and store the Putextra object by intent the value to be transferred
The end of the 3.listener interface implementation, the intent object is invoked via Activity01, and is switched to ACTIVITY02
4. In Activity02, use getintent to get the instance of the intent object in the context switch that makes itself bootable
5. With the intent object instance obtained, use the Getstringextra to get the value of the previous Putextra.
Of course, if you know more about intent in the future, you need to pick a more appropriate function for storing data and getting the data according to the actual situation.
The following is a demonstration of the implementation:
Finally, attach the key part code:
In Activity01:
Button.setonclicklistener (new Button.onclicklistener () {///More accurate point should be View.onclicklistener void OnClick ( View v) { /* Create a new Intent object * /New Intent (); Intent.putextra ("name",/* Specifies intent to start the class */Intent.setclass (Activity01. This, Activity02. / * Start a new activity */ACTIVITY01. / * Close the current Activity */ACTIVITY01. this.finish ();}});
In Activity02:
String Name=intent.getstringextra ("name"); Textview2.settext ("Activity01 passed the value is:" +name);
Android Activity switch