Android app application startup analysis and Optimization _android

Source: Internet
Author: User

How the app starts:
1.) Lengqi move
When the application is started, the background does not have the application process, then the system will re-create a new process assigned to the application, this startup mode is cold start. Cold start because the system will re-create a new process to assign it, it will first create and initialize the application class, then create and initialize the Mainactivity class (including a series of measurements, layouts, drawings), and finally display it on the interface.
2.) Hot start
When you start an application, there is already a process for that application in the background (example: Press the back key, the home key, although the application will exit, but the application process is still kept in the background, can go to the task list to view, so in the case of existing processes, this startup will start the application from the existing process, this way called hot start. Hot start because it will start from the existing process, so hot boot will not go application this step, but go directly mainactivity (including a series of measurement, Layout, drawing), so the hot start process only to create and initialize a mainactivity on the line, Instead of creating and initializing application, the application is initialized only once, because one application is created from the new process to the process's destruction.

app's startup process:
You can see from the above two startup ways that the app startup process is:
Application Constructor Method-->attachbasecontext ()-->oncreate ()-->activity construction Method-->oncreate ()--> Properties such as backgrounds in Configuration Topics-->onstart ()-->onresume ()--> measurement layout drawing appears on the interface

Startup optimizations for Apps:
based on the above boot process we try to do the following points
Minimal time consuming operations during the creation of 1.Application
2. If you use Sharepreference, try to operate in an asynchronous thread
3. Reduce the level of layout, and the life cycle callback method to minimize time-consuming operations

App startup meets black screen or white screen problem
1.) cause
In fact, the display of black screen or white screen is normal, because it has not been loaded into the layout file, it has been shown window windows background, Black Screen screen is window windows background.
Example:

2.) Solutions
set style by setting
(1) Setting the background figure theme
By setting a background picture. When the program starts, first display this background image to avoid the black screen

<style name= "Apptheme" parent= "Theme.AppCompat.Light.DarkActionBar" >
    <item name= "Android: Screenorientation ">portrait</item>
    <item name=" Android:windowbackground ">> @mipmap/splash </item>

    <item name= "android:windowistranslucent" >true</item>
    <item name= "Android: Windownotitle ">true</item>
</style> 

(2) Set up transparent theme
By setting the style to transparent, the program does not start black screen but the whole is transparent, wait until the interface is initialized to display it once

<style name= "Apptheme" parent= "Theme.AppCompat.Light.DarkActionBar" >
    <item name= "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> 

Comparison between the two:
The THEME1 program starts fast, the interface first displays the background image, and then refreshes the other interface controls. Give people a refreshing feeling of not being synchronized.
Theme2 gives the program start slow feeling, the interface brushes out once, refreshes the synchronization.
(3) Modify Androidmanifest.xml

 <application
    android: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> 

Example after resolution:

3.) Common Theme Themes

Android:theme= "@android: Style/theme.dialog"//activity displayed as 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 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"//with System desktop for application background

Android:theme= "Theme.Wallpaper.NoTitleBar"//with System desktop for application background with 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= "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"//Flat style display
Do we this line, when slack, means that the cessation of progress, the cessation of the improvement means to be eliminated, only forward, until the Phoenix Nirvana Day!

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.