Http://mobile.51cto.com/android-265546.htm
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 and 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 meaning of activating the account
// Method 1 obtain the parameter 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
// Statement 1: intent. setclass (mainactivity. This, otheractivity. Class );
// Set the component to be activated
// Statement 2: intent. setcomponent (New componentname (mainactivity. This, otheractivity. Class ));
// Set the component to be activated
When an opened activity is closed, the following method is used to open the activity:
- Startactivityforresult (intent, 10); // is the request 10 when the opened intent is disabled?
Intent intent2 = new intent (); intent2.putextra ("result", "this is the result of disabling returned"); setresult (10, intent2 ); // 10 is the return code finish (); // close the activity
Override of opened Activity
- /**
- * When an opened activity is disabled
- * 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 );
- }