The first line of code: Android Guo Lin (2.2) basic usage of activity
- Hide title bar
- Configured in Androidmanifest.xml, as a global configuration, takes effect within all activity scopes
- Android:theme= "@android: Style/theme.notitlebar"
- Configured in code, the method must be called before Setcontentview (), only if the current activity is active
- Requestwindowfeature (Window.feature_no_title);
- Set in Style.xml
2.3 Intent Application Scenarios
- Activity
- Service
- Broadcastreceiver
2.3.1 Explicit Intent
- Intent Intent = new Intent (currentactivity.this, Nextactivity.class);
- StartActivity (Intent);
- Explicitly specify the next Activity
2.3.2 Implicit Intent code creates intent objects without explicitly pointing to specific activity. The action/category/data of the intent object is set, and when startactivity (intent) is called, the system calls the Androidmanifest.xml registered in activity,< The action/category/data specified in the intent-filter> must be exactly the same as the code's settings.
- Action
- Intent Intent = new Intent (Intent.action_view);
- The Action_view here is the action. Each intent object has only one action, which can be customized
- Intent.action_view Response to open browser action
- Intent.action_dial response call "dialing" action
- Category
- Intent.addcategory ("My_category");
- Add category with Addcategory (), each intent object can be set to multiple category , customizable
- Data
- More precisely specify the type of intent the activity can respond to, setting multiple data
- Android:scheme
- Android:host
- Android:mimetype
- etc.
Transfer data between 2.3.4 activity (set activity A to B pass data)
- is passed through intent in the form of key-value, such as the HashMap object
- Intent.putextra ("My_key", value);
- a replace startactivity () with Startactivityforresult () and pass in Requestcode Identity (flag)
- Startactivityforresult (Intent, Requestcode) when the data returned by the other activity is received as a;
- b obtains data by obtaining the Intent object passed by a
- Intent Intent = Getintent ();
- String data = Intent.getstringextra ("My_key");
- If B is going to return data to a, you need to add ReturnCode
- Intent Intent = new Intent ();
- Intent.putextra (key, value);
- Setresult (RESULT_OK, intent);
- finish ();
- A processes data that is returned by B in Onactivityresult ()
- using a switch statement based on Requestcode
- can root According to ResultCode ( result_ok/result_cancel)
- B Pass data when you click the back key
- overwrite Onbackpresse D ();
- super.onbackpressed (); Be sure to comment out or put at the end, otherwise you will return directly in this step
The first line of code: Android Learning Note: Activity & Intent