Android Cold start Optimizer

Source: Internet
Author: User

Android Cold boot optimization 1. What is cold start

Cold start is the case when the application is first started or the application is killed (not in memory) and then started again.
You may have noticed that the startup time will be slightly longer in this case. Because it will initialize the resource again (application, etc.).

When the app starts, it usually initializes in application or so-called splashactivity.

Suppose there is too much work in the application. So when the cold starts. There will be a 白屏 situation. Because SplashActivity it has not been initialized at this time. SplashActivitythe picture on it hasn't been shown yet.

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

The solution should be considered in two ways, and 1 is the Application initialization logic of the optimization. This asynchronous asynchronous, for example, delays 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 , for example the following:

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 , the same time the property is replicated windowBackground , its value SplashActivity will show the picture (logo and so on ...).

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 SplashActivity set a background map for more, it is bound to cause the transition to draw, so we before its initialization. Set the theme back to the original:

@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 白屏 .

References:
    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.