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 parameter transfer 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 it
// Method 1 get the parameter String name = intent. getStringExtra ("name"); int age = intent. getIntExtra ("age", 0); // method 2 get the Parameter
Int age = intent. getExtras (). getInt ("age ");
String name = intent. getExtras (). getString ("name ");
Set the component to be activatedIntent intent = new Intent (MainActivity. this, OtherActivity. class); // set the component to be activated for intent // Method 1: intent. setClass (MainActivity. this, OtherActivity. class); // set the component to be activated // Method 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 );
- }
Android Study Notes: Activity jump
Insert a new Activity in Android Development
Android development: Passing values between activities
Android Application Development Tutorial: communication between two running activities