Android process keep alive --- start page black screen and optimal solution (2)

insert image description here
Android process keep alive (1)

Android process keep alive --- start page black screen and optimal solution (2)

Know the specific solution by reading the previous article. 黑屏The situation mentioned above will appear.
In the actual measurement of Android 6.0, 8.0, 9.0, 11.0, and 12.0, there will be a black screen. The specific details are as follows:

In the above, a 1-pixel activity was created ; when using 1-pixel, you only need to start an activity in this process when the screen is locked or black , and another problem is involved here:

foreword

I believe that friends who have done Android know that when an APP is started, the interface will first display a white or black screen, then enter the welcome page, stop for a while and finally enter the APP home page. So what is going on with this black screen or white screen? What would be the best solution for it?

Historical reasons

When the system starts an APP, the zygote process will first create a new process to run the APP, but the creation of the process takes time. Before the creation is completed, the interface is in a suspended state, which is very embarrassing, because You will think that you have not clicked on the APP and click again, which greatly reduces the user experience. Android needs to give feedback in time to avoid this embarrassing embarrassment. So the system displays a white screen or a black screen according to the theme color set in your manifest file. And the official name of this black (white) screen should be Preview Window , ie 预览窗口.

review

We review the 1-pixel activity. In the case of monitoring the lock screen/off screen, when the user opens the application, a black screen will appear; only when the user clicks the system back button will the normal situation return. In this case, we have not set the theme .

So what is the solution to this?

Solution:

Now that you have decided to solve this problem, where do you start? When Android chooses to display a black screen or a white screen, it is different according to the theme you set. That is to say, although your code is not executed, your configuration file However, it was read in advance and used as a basis for displaying the Preview Window interface.

Therefore, the entry point of our solution is the manifest file of the entire APP, more precisely, it should be the theme configuration file.

Option One:

Prohibit loading the Preview Window, the specific method is as follows: style.xml

<style name="APPTheme" parent="@android:style/Theme.Holo.NoActionBar">
   <item name="android:windowDisablePreview">true</item>
</style>

Setting APPTheme as the theme of the started Activity will disable the Preview Window. But this method is not very ideal in terms of user experience; when 1 pixel monitors the opening/brightening of the screen, it will call up the active page, and every time it is called again, the screen will be black.

Option II:

Set the preview window to full transparency, there is no animation for window switching, and no theme is included.

   <style name="APPTheme" parent="@android:style/Theme.Holo.NoActionBar">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:windowNoTitle">true</item>
    </style>

Solution 3: Customize the Preview Window

The specific method is as follows: style.xml

<style name="APPTheme" parent="@android:style/Theme.Holo.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_icon</item>
</style>

Also set the theme to the theme of the started Activity, windowBackground is the preview window to be displayed. Among them, splash_icon can be a whole picture, and many friends on the Internet also do this. In fact, it can also be an XML file that can parse out image resources. It seems that only layer-list can do it, because it can superimpose multiple drawables for display.

splash_icon.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="@color/white"/>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/qq"/>
    </item>
</layer-list>

After this setting, when you click on the APP, you will immediately enter the interface you configured, and then start the welcome page.

This solution is to change the switching of two interfaces into one interface.

If you want to further improve the display effect, how can you make the switching between the two interfaces look like a change in the same interface? can join 动画.



Recently, I took a break from my busy schedule, ↓↓↓↓[Who’s De Code Farmer Mr. Chen]↓↓↓↓, I will share technical blog posts and high-energy information content with you regularly! Welcome all bosses to like and follow, you are my source of motivation!

Guess you like

Origin blog.csdn.net/chen_md/article/details/128896187