Overview of the splash screen
Splash screen. Almost every APP on our phones has its own splash screen, where a page pauses for a few seconds before actually entering the application. In fact, we could have made the most of those seconds by doing a lot of initialization.
Why does my APP get a blank or black screen when it starts
Sometimes we find that when we launch our own APP, there is always a blank screen (black screen) for a short period of time, after the blank screen (black screen) will enter our APP. So why is this?
Simulation results
Now let’s simulate the effect of a white screen
It can be seen that there will be a blank screen when OPENING the APP. Of course, my demo APP is not that complicated, so I took a sleep in the Application to achieve this effect.
@Override
public void onCreate(a) {
super.onCreate();
myApplication = this;
try {
Thread.sleep(2000);
} catch(InterruptedException e) { e.printStackTrace(); }}Copy the code
Therefore, it can be concluded that if the program is very complex and a lot of initialization has been completed in the Application, it will take time to open the program and the effect of white screen will appear.
When an Activity is started and the Application to which it belongs is not yet running, the system first creates a process for the Activity. Application’s onCreate method is called when the process is created. The process creation and initialization of onCreate takes time. If this time is too long and there is no response, then the user will not be aware of it. The user will not be able to wait for the original page to load. StartingWindow(PerviewWindow) is a temporary window that appears before the application process is created and initialized. The corresponding WindowType is TYPE_APPLICATION_STARTING, which tells the user that the system has received our action, is initializing the application, and will remove the window as soon as the initialization is complete.
So the white or black screen we see is StartingWindow, so why white or black? We usually set a Theme for our Application and Activity, and the system will use the Theme to determine the StartingWindow color. We all know that the top layer of the Window layout is a DecorView, and that StaringWindow displays an empty DecorView, except that this DecorView applies the Theme specified by our Activity. We the default Theme is @ android: style/Theme. The Light, can produce white during this time. Black screen is applied the @ android: style/Theme. Black, okay, here we can completely understand why white or Black screen. By the way, the order in which the Activity layout is drawn:
- Draw the background
- Draw the contents of the View itself
- Draw the son View
- Draw modifiers (such as scroll bars)
Solve the problem of black and white screen
We already know why this problem occurs, so it is easy to solve, just need to add a background to the style of the launch page, so that the effect of the second!
<style name = "SplashThem" parent = "AppTheme">
<item name = "android:windowBackground">@drawble/splash</item>
<item name = "android:windwoFullscreen">true</item>
</style>Set this background to match my launch page!Copy the code
Reference: blog.csdn.net/yanzhenjie1…