※application
Each time the application runs, the application class remains instantiated, and the application is implemented as a single State (singleton), extending as follows:
Import *;
public class MyApplication extends application{
private static MyApplication Singleton;
public static MyApplication Getintance () {
return singleton;
}
Creating an application is called, instantiating an application form, creating and instantiating a state variable, or sharing a resource
@Override
Public final void OnCreate () {
Super.oncreate ();
Singleton = this;
}
Empty the cache and unnecessary resources when the system is in a resource-scarce state
@Override
Public final void Onlowmemory () {
Super.onlowmemory ();
}
Called when the system decides to reduce memory overhead, including a level parameter, which is never provided in the request context
@Override
Public final void Ontrimmemoy (Int. level) {
Super.ontrimmemoy (level);
}
@Override
When an application uses a value that relies on a specific configuration, the overrides are reloaded to reload the values.
Public final void onconfigurationchanged (Configuration newconfig) {
Super.onconfigurationchanged (Newconfig);
}
}
※ Optimized layout
1. When the layout containing the merge label is added to another layout, the merge of the layout is deleted.
Using the include tag to add a layout contained in the merge label to another layout creates a flexible, reusable layout definition.
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical" >
<include android:id= "@+id/my_image_text_layout"
layout= "@layout/image_text_layout"
</LinearLayout>
Image_text_layout.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<merge
Xmlns:android= "Http://schemas.android.com/apk/res/android" >
<imageview
Android:id= "@+id/image"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
/>
<textview
Android:id= "@+id/text"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "@string/hello"
Android:gravity= "Center_horizontal"
android:layout_gravity= "Bottom"
/>
</merge>
2. Avoid using multiple view, the layout contains the number of view does not change more than 80. Want to fill a view in a complex layout
A small number of viewstub can be used. Equivalent to a deferred include tag that is populated only if the displayed call inflate () method or is set to visible.
View stub = Findviewbyid (R.id.id_stub);
Stub.setvisibility (view.visible);
View instub = Findviewbyid (r.id.id_in_stub)
Viewstub stub = (viewstub) Findviewbyid (R.id.viewstub_demo_text);
Stub.inflate ();
The Layout property is an XML file that needs to be populated.
<viewstub
Android:id= "@+id/id_stub"
Android:inflatedid= "@+id/id_in_stub"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout= "@layout/viewstub_layout"/>
Beginner _ANDROID4 Advanced Programming-1 application single case, and optimized layout