Objective:
Last night the new version was finally released, but still remember that the test feedback app has been launched for a long time and did not enter the app homepage, so prepare to add a class today to summarize the app launch those things!
How to start the app: 1.) Cold start
When the app is launched, there is no process for the app in the background, and the system will recreate a new process to assign to the app, starting with a cold boot. Cold start because the system re-creates a new process to assign it, the application class is created and initialized, and the Mainactivity class (including a series of measurements, layouts, drawings) is created and initialized, and finally displayed on the interface.
2.) Hot start
When the app is launched, the app's process is already in the background (example: Press the back key, the home key, the app exits, but the app's process is still in the background and can be viewed in the task list), so in the case of an existing process, this startup starts the app from the existing process. This method is called hot start. Hot start because it will start from the existing process, so the hot start will not go application this step, but directly go mainactivity (including a series of measurement, Layout, drawing), so the hot start process only need to create and initialize a mainactivity on the line, Instead of creating and initializing application, because an application is created from the new process to the destruction of the process, application is initialized only once.
App start-up process:
The application start-up process can be seen through the above two startup methods:
Application constructor Method-->attachbasecontext ()-->oncreate ()-->activity construction Method-->oncreate ()-- > Config theme in the background etc Properties-->onstart ()-->onresume ()--Measurement layout drawing display on interface
App Start-Up optimization:
Based on the above start-up process, we try to do the following.
ApplicationAs few time-consuming operations as possible during the creation of
If used SharePreference , try to operate in an asynchronous thread
Reduce the level of layout and minimize time-consuming operations in the life cycle callback approach
App startup meets black screen or white screen issue 1.) cause
Actually displays the black screen or the white screen is normal, this is because has not loaded to the layout file, already displayed the window Windows background, the black Screen white screen is the window Windows background.
Example:
2.) Workaround
Set style by setting
(1) Setting the background map theme
By setting a background map. When the program starts, this background image is displayed first to avoid a black screen
<stylename= "Apptheme"Parent= "Theme.AppCompat.Light.DarkActionBar"> <Itemname= "Android:screenorientation">Portrait</Item> <Itemname= "Android:windowbackground">> @mipmap/splash</Item> <Itemname= "Android:windowistranslucent">True</Item> <Itemname= "Android:windownotitle">True</Item></style>
(2) < Span class= "title" > Set Transparent theme
by setting the style to transparent, the program will not black screen after startup, but the whole transparent, wait until the interface is initialized to show it once
<stylename= "Apptheme"Parent= "Theme.AppCompat.Light.DarkActionBar"> <Itemname= "Android:windownotitle">True</Item> <Itemname= "Android:windowbackground">@android: Color/transparent</Item> <Itemname= "Android:windowistranslucent">True</Item> <Itemname= "Android:screenorientation">Portrait</Item> </style>
Compare the two:
The THEME1 program starts quickly, the interface displays the background map first, and then refreshes the other interface controls. Give people a refreshing feeling of being out of sync.
Theme2 give the program start slow feeling, the interface once brush out, refresh synchronization.
(3) Modify Androidmanifest.xml
<ApplicationAndroid:name=". App "Android:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"> <ActivityAndroid:name=". Mainactivity "Android:theme= "@style/apptheme"> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> //......</Application>
Post-resolution Example:
3.) Common Theme Themes
Android:theme= "@android: Style/theme.dialog"//activity displayed as Dialog mode Android:theme= "@android: Style/theme.notitlebar"// Do not display the application title bar Android:theme= "@android: Style/theme.notitlebar.fullscreen"//Do not display the application title bar and full screen android:theme= "Theme.light "//Background is white android:theme=" Theme.Light.NoTitleBar "//white background with no title bar android:theme=" Theme.Light.NoTitleBar.Fullscreen "// White background, no title bar, full screen android:theme= "theme.black"//Background black android:theme= "Theme.Black.NoTitleBar"//black background with no title bar Android:theme= " Theme.Black.NoTitleBar.Fullscreen "//black background, no title bar, full screen android:theme=" Theme.wallpaper "//Use System desktop for application background android:theme=" Theme.Wallpaper.NoTitleBar "//Use System desktop for application background with no title bar android:theme=" Theme.Wallpaper.NoTitleBar.Fullscreen "// Use System desktop for application background, no title bar, full screen android:theme= "theme.translucent"//Transparent background android:theme= "Theme.Translucent.NoTitleBar"// Transparent background with no title android:theme= "Theme.Translucent.NoTitleBar.Fullscreen"//Transparent background with no title, full screen android:theme= "Theme.panel"// Panel style display Android:theme= "Theme.Light.Panel"//Tablet style display
Android app launch analysis and optimization