In Android, each activity generally describes all the pictures on a screen (except for window-level activity). Therefore, two screens on a mobile phone are usually used (the whole screen is accurate) activity switching is involved.
Assume that there are two activities, activity01 and activity02. Now there is a button in the activity01 page. After clicking it, it switches to activity02. during activity switching, activity01 passes a parameter to activity02. (intent can be used when switching activity and data can be transferred .)
How can this problem be solved? The general idea is:
1. Set a trigger space in activity01 and add a trigger
2. Add a listener to the activity01 trigger.
3. In the listener interface implementation, set an intent so that the intent can bind activity01 and activity02 and put the value to be transmitted through putextra into the intent object for storage.
3. At the end of the listener interface implementation, start and call the intent object through activity01, and switch to activity02 through the call.
4. In activity02, use getintent to obtain the intent object instance that has been started in context switching.
5. Use getstringextra to obtain the previous putextra value through the obtained intent object instance.
Of course, if you know more about intent later, you need to select a more suitable function to store and obtain data based on the actual situation.
The following is an implementation Demonstration:
The following code is attached:
In activity01:
Button. setonclicklistener (New button. onclicklistener () {// view is more accurate. onclicklistener public void onclick (view v) {/* Create an intent object */intent = new intent (); intent. putextra ("name", "Leipei");/* specifies the intent class */intent. setclass (activity01.this, activity02.class);/* start a new activity */activity01.this. startactivity (intent);/* close the current activity */activity01.this. finish ();}});
In activity02:
String name = intent. getstringextra ("name"); textview2.settext ("the value passed by activity01 is:" + name );