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:
- Https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd
Android Cold start Optimizer