Android Cold start Optimizer

Source: Internet
Author: User

Android Cold boot optimization 1. What is cold start

Cold start refers to the case where the application was first started or the application was killed (not in memory) after restarting.
You may have found that the startup time will be slightly longer in this case. Because it will reinitialize resources (application, etc.).

When the app starts, it usually initializes in application or so-called splashactivity. If there is too much work in the application, then when the cold starts, it will happen 白屏 , because it has SplashActivity not been initialized, SplashActivity the picture has not been displayed.

We certainly do not want 白屏 the situation to arise.

The solution should be considered in two ways, 1 is the initialization logic of the optimization Application , such as asynchronous asynchronous, delay of the delay. 2 is to be 白屏 replaced SplashActivity in the display of the picture, so that users have an application has been started the illusion, this article is about this optimization scheme.

2. How to Optimize

We need to SplashActivity set one Theme , as follows:

Styles.xml

name="AppTheme.Launcher">        <itemname="android:windowBackground">@drawable/launch_screen</item>        <itemname="android:windowFullscreen">true</item> </style>

This Theme inherits the basic theme of the app AppTheme , and windowBackground It also copies the properties, and its value is the SplashActivity picture (logo, etc.) that will be displayed.

Launch_screen.xml

<?xml version= "1.0" encoding= "Utf-8"?><layer-list xmlns:android="Http://schemas.android.com/apk/res/android"  Android:opacity="opaque">        <item android:drawable="@android: Color/white"/>    <!--Your product LOGO-144DP color version of Your app icon --    <item>        <bitmapandroid:src= "@drawable/splash_defalut"android:gravity=" Fill "/>                            </Item></layer-list>

Then set this topic to the SplashActivity top:

 <activityandroid:name=". Ui.activity.SplashActivity"android:configchanges ="Fontscale"android:screenorientation= "portrait"android:theme="@ Style/apptheme.launcher " >                                        <intent-filter>            <action android:name="Android.intent.action.MAIN" />            <category android:name="Android.intent.category.LAUNCHER" />        </intent-filter></activity>

This is not finished, because we set up a SplashActivity background map, which will inevitably lead to transitions drawn, so we set the theme back to the original before it initializes:

@Override    protectedvoidonCreate(Bundle savedInstanceState) {        setTheme(R.style.AppTheme);        super.onCreate(savedInstanceState);        setContentView(R.layout.splash_activity);

Above.

Now you will find that even if the boot time is longer, it will not appear 白屏 .

Reference:
    1. Https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd

Android Cold start Optimizer

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.