text
I believe you must have encountered some apps that will have a brief or few seconds of white screen when opening the desktop of your mobile phone. That's right, that's the default background color of the system after the application is started. At this time, the first activity of the application has not been loaded yet, so no matter how you set the background color of the first activity, it has no effect. But careful friends found that the white screen time of some apps is very short when they start, which is almost negligible? Today I will share an article about the problem of the long time that the App is cold-starting to handle white screens.
Let’s talk about cold start and hot start first:
- Cold start
Kill the App. At this time, the App process does not exist in the background. It starts from the Logo page.
- Hot start
The app is in the background and the process has not been killed. When you re-enter the foreground, the page remains the last page and will not restart.
Therefore, what we are talking about this time is a cold startup process. When the application code is small, the business logic is small, and the volume is small, the App starts relatively quickly, and the white screen time can be ignored. Once there are too many initialization tools and too many home page business logic, the startup speed will be severely slower, and the white screen time will become longer and longer, giving people an extremely poor experience. All we need to do is to display icons such as logos as quickly as possible during white screen time, so that it becomes a transition, and jump to the corresponding page after the application is ready to improve the user experience.
Configure a SplashActivity
First, you need to configure a theme of SplashActivity (the first Activity displayed by the application)
<style name="SplashTheme" parent=""> <!-- WillsplashThe picture is set here,This image replaces the white screen --> <item name="android:windowBackground">@drawable/logo_drawable</item> <item name="android:windowAnimationStyle">@style/notAnimation</item> <!--Will顶部状态栏设置为透明,并Will界面内容布局上边界上提至状态栏顶部--> <item name="android:windowTranslucentStatus">true</item> <!--If there is a bottom virtual navigation bar,则Will底部虚拟导航栏设置为透明,并Will界面内容布局下边界下沉至虚拟导航栏底部--> <item name="android:windowTranslucentNavigation">true</item> <item name="android:windowFullscreen">true</item> <item name="android:windowNoTitle">true</item> <item name="windowActionBar">true</item> </style>
Among them, windowBackground is our key configuration this time, and windowAnimationStyle is to cancel some animation effects of the page. Generally, we make it without animation on the home page, and other settings can be set according to your own situation.
Let's take a look at logo_drawable
<layer-list xmlns:andro> <item> <color android:color="#ffffffff"/> </item> <item android:top="208dp" android:bottom="453dp"> <bitmap android:gravity="center" android:src="@mipmap/ic_logo" /> </item> </layer-list>
A bitmap is superimposed on a white background. It should be noted here that the item tags on the outer layer of the bitmap must be configured with the upper and lower margins according to the design draft, otherwise the effect after running the App will be covered with the screen.
Then we configure the above topic into the activity. At this time, the layout file of SplashActivity can be written without writing anything, because the theme is equivalent to the background. If the page written here may coincide with the background logo, you only need to write some logic and jump processing.
<activity android:name="." android:configChanges="orientation|screenSize" android:exported="true" android:launchMode="singleTop" android:screenOrientation="portrait" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity>
At this point, when I ran the app again, I found that almost clicked on it was the logo we configured, which perfectly handled the white screen problem.
Notice:
If the project uses a three-party library that is adapted to UI, such as android AutoSize, remember to give up the startup page adaptation according to the document processing, otherwise the results of the operation will not be satisfactory.
Summarize
The white screen processing is actually to configure a background through the theme. When the page is loaded, the background will be displayed first, without rendering the page. Therefore, the logo can be displayed quickly after the app is opened. Generally, it will be delayed by one or two seconds before jumping to the homepage to achieve a good user experience.
The above is the detailed explanation of the Android application launch white screen processing solution. For more information about Android application launch white screen processing, please pay attention to my other related articles!