Acitvity Development
A. Configuration File
<Activity Android: Name = ". otheractivity" Android: Label = "otheractivity">
</Activity>
B. Write layout files
C. Write a class to inherit the activity
Override oncreate
In this method, set the layout file setcontentview (R. layout. Other );
Activity Parameters
// Method 1 for passing parameters with Intent
// Intent. putextra ("name", "Tan Jianping ");
// Intent. putextra ("Age", 25 );
// Method 2
Bundle bundle = new bundle ();
Bundle. putstring ("name", "Tan Jianping ");
Bundle. putint ("Age", 25 );
Intent. putextras (bundle );
Intent intent = This. getintent (); // get the intent to activate it
// Obtain parameters in method 1
String name = intent. getstringextra ("name ");
Int age = intent. getintextra ("Age", 0 );
// Obtain parameters in method 2
Int age = intent. getextras (). getint ("Age ");
String name = intent. getextras (). getstring ("name ");
Set the component to be activated
Intent intent = new intent (mainactivity. This, otheractivity. Class); // set the component to be activated for intent
// Write Method 1: intent. setclass (mainactivity. This, otheractivity. Class); // set the component to be activated
// Statement 2: intent. setcomponent (New componentname (mainactivity. This, otheractivity. Class); // you can specify the component to be activated.
Returned value when the opened activity is disabled
The method to open an activity is
Startactivityforresult (intent, 10); // is the request 10 when the opened intent is disabled?
When the opened activity is closed
Intent intent2 = new intent ();
Intent2.putextra ("result", "this is the result of disabling returned results ");
Setresult (10, intent2); // 10 is the return code.
Finish (); // close the activity
rewrite an opened activity
/**
* When the opened activity is closed
* requestcode Request Code
* resultcode return code
* The Request Code and return code are used to differentiate multiple activities during a jump
*/
@ override
protected void onactivityresult (INT requestcode, int resultcode, intent data) {
toast. maketext (this, Data. getstringextra ("result"), toast. length_short ). show ();
super. onactivityresult (requestcode, resultcode, data);
}