"Reprint" Android app launch analysis and optimization

Source: Internet
Author: User

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 (for 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, which 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:

The constructor method of the application-->attachbasecontext ()-->oncreate ()-->activity is constructed by-->oncreate () and the properties of the background in the configuration theme- ->onstart ()-->onresume ()---Measurement layout drawing is displayed on the interface

App Start-Up optimization:

Based on the above start-up process, we try to do the following.

    1. ApplicationAs few time-consuming operations as possible during the creation of
    2. If used SharePreference , try to operate in an asynchronous thread
    3. 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> <item name= "Android:windowbackground" >> @mipmap/splash</item> <item Span class= "hljs-attr" >name= "android:windowistranslucent" >true </item> < item name= "Android:windownotitle" > True</item></ STYLE>             

(2) 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> <item name=  "Android:windowbackground" > @android: Color/transparent</ item> <item name= "android:windowistranslucent" >true </item> < item name= "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" ><activity android:name=". Mainactivity "android:theme=" @style/apptheme "> <intent-filter> < Action android:name= "Android.intent.action.MAIN"/> <category android:name=  "Android.intent.category.LAUNCHER"/> </ intent-filter> </activity>// ...... </APPLICATION>        

Post-resolution Example:

3.) Common Theme Themes
Android:theme="@android: Style/theme.dialog"Activity is displayed as a dialog box 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 for 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"Black android:theme= Background"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" //with System desktop for application background Android:theme=" Theme.Wallpaper.NoTitleBar "//with System desktop for application background, and no title bar Android:theme= "Theme.Wallpaper.NoTitleBar.Fullscreen" //with System desktop for application background, no title bar, Full screen Android:theme= "theme.translucent" //Transparent background android:theme=< Span class= "hljs-string" > "Theme.Translucent.NoTitleBar" //Transparent background with no caption 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       

Dry our line, when slack, means that the cessation of progress, the cessation of progress means to be eliminated, only forward, until the Phoenix Nirvana Day!

"Reprint" Android app launch analysis and optimization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.