Links to the original text: http://blog.csdn.net/feiduclear_up/article/details/78822775
When Android launches Activity across processes, the process interface is very black (white) for a short time (hundreds of milliseconds?). Of course, the same thing happens when you start an App from a desktop Lunacher, because the cold start of App is also a cross-process start activity. Why hasn't this happened? The real culprit is that the Android creation process requires a lot of resources, which is a time-consuming operation.
Reasons for Black Screen (White Screen)
When process A starts an activity in process B, the Android system will have Zygo process to create process B before starting the activity. However, the creation process is time-consuming. Before the creation is completed, the new Activity interface has not yet been shown, so that the user will not respond to the jump of the new Activity for a short time, which greatly reduces the user experience.
The Android team avoids this awkward situation, so the system displays a white or black screen based on the color of the theme set in your manifest file. This black (white) screen is called Preview Window, or Preview Window.
Solution
1. Disable Preview Window
Since Android defaults to Preview Window when creating a process to start a new Activity, we can also disable this property in the theme.
style.xml
<style name="APPTheme" parent="@android:style/Theme.Holo.NoActionBar"> <item name="android:windowDisablePreview">true</item> </style>
Analysis: This can solve the problem of some scenarios, such as Activeness in process A and process B, but in another scenario, there is a problem, and there is a temporary false death in Launcher click application on the desktop.
2. Custom Preview Window
Since Android can set the Preview Windows black screen (white screen) according to the theme, we can also customize a Preview Windows style to replace the black (white) screen effect.
style.xml
<style name="APPTheme" parent="@android:style/Theme.Holo.NoActionBar"> <item name="android:windowBackground">@drawable/splash_icon</item> <item name="android:windowFullscreen">true</item> <item name="android:windowNoTitle">true</item> </style>
Analysis: This solution is very suitable for launching an App scenario. Android: Windows Background property sets the background of Preview Window s. Most Apps on the market use this property to set the background of the startup page. For memory savings, this background image is suitable for the use of simple. 9 images.
However, this solution is not suitable for launching Activity scenarios across processes.
3. Setting Preview Window s Transparency Properties
We can set Preview Window s to be transparent, or we can solve the problem.
style.xml
<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:windowFullscreen">true</item> <item name="android:windowNoTitle">true</item> </style>
Analysis: This solution is suitable for cross-process startup activity scenarios. Of course, this solution will introduce other problems, that is: Android: Windows Is Translucent causes the activity switching animation invalid solution. In order to pursue the ultimate goal, it is impossible to solve a problem by introducing a new problem. There are also two solutions to this problem:
- Code Dynamic Setting Activity Special Animation
overridePendingTransition(R.anim.anim_right_in,R.anim.anim_left_out);
- Set animation style for Window s
<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:windowFullscreen">true</item> <item name="android:windowNoTitle">true</item> <item name="android:windowAnimationStyle">@styleAnimation.Activity.Translucent.Style/</item> </style> <style name="Animation.Activity.Translucent.Style" parent="@android:style/Animation.Translucent"> <item name="android:windowEnterAnimation">@anim/base_slide_right_in</item> <item name="android:windowExitAnimation">@anim/base_slide_right_out</item> </style>
Since then, three schemes for cross-process activation of Activity black (white) screen have been given, and the viewer can use the above different solutions according to different scenarios.
Sweep code pays attention to the public number "Android knowledge dissemination" of Wechat, and periodically disseminates the commonly used Android basic knowledge.