English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
前言
我相信很多Android开发同学都遇到过这样的需求:
1.实现一个Splash界面,界面上有应用相关的背景图片和一个开始按钮。
2.点击按钮之后进入主页,以后用户再打开应用就不显示这个Splash界面了。
也相信很多同学都遇到了这样的困惑:
•第二次进入应用,尽管你在Splash界面已经直接跳转到首页了,但是还是有个白屏或者黑屏或者带ActionBar的白屏闪现一下。
如果你也遇到这个问题,那就继续阅读这篇文章,我带大家去分析和解决这个问题。
解决方案
这里我们先给出解决方案,然后再具体分析产生原因哈。避免分析的大段文字阻碍了同学学习的热情。
解决方案非常简单,一句话概括是:给Splash Activity设置一个主题,主题内容是:全屏+透明.
style.xml增加SplashTheme主题:
<style name="SplashTheme" parent="AppTheme"> <item name="android:windowFullscreen">true</item> <item name="android:windowIsTranslucent">true</item> </style>
AndroidManifest.xml中为SplashActivity配置主题:
<activity android:name=".activity.SplashActivity"> android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN"> /> <category android:name="android.intent.category.LAUNCHER"> /> </intent-filter> </activity>
With the above configuration, the white screen, black screen, and ActionBar screen that have been bothering you should have disappeared. To understand not only the phenomenon but also the cause, I hope that the students can continue to analyze with me the reasons for the white screen.
The window startup process of the Activity component
Firstly, it is declared that this section of content has drawn heavily on Professor Luo Shengyang's blog. For the sake of understanding, the content has been compressed. If there is any infringement, I will immediately delete this analysis.
To understand the root cause of the white screen, it is necessary to trace the window startup process of the Activity component. During the startup process, the Activity component calls the startActivityLocked method of the ActivityStack class. Note that when calling the startActivityLocked method of the ActivityStack class, the Activity component is still in the startup process, that is, its window has not yet been displayed, but at this time, the ActivityManagerService service will check whether it is necessary to display a startup window for the Activity component that is being started. If necessary, the ActivityManagerService service will request the WindowManagerService service to set a startup window for the Activity component that is being started (ps: this startup window is the origin of the white screen).
1. ActivityStack.startActivityLocked
public class ActivityStack { // set to false to disable the preview that is shown while a new activity // is being started. static final boolean SHOW_APP_STARTING_PREVIEW = true; private final void startActivityLocked(ActivityRecord r, boolean newTask, boolean doResume) { final int NH = mHistory.size(); int addPos = -1; // Place to new activity at the top of the stack, so it is next to interact // with the user. if (addPos < 0) { addPos = NH; } // Slot the activity into the history stack and proceed mHistory.add(addPos, r); if (NH > 0) { // We want to show the starting preview window if we are // switching to a new task, or the next activity's process is // not currently running. boolean showStartingIcon = newTasks; ProcessRecord proc = r.app; if (proc == null) { proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); } if (proc == null || proc.thread == null) { showStartingIcon = true; } } } }
To be continued...Hope everyone continues to pay attention.
That's all for this article, I hope it will be helpful to everyone's study, and I also hope everyone will support the Yelling Tutorial more.
Declaration: The content of this article is from the Internet, the copyright belongs to the original author, the content is contributed and uploaded by Internet users spontaneously, this website does not own the copyright, has not been manually edited, and does not assume any relevant legal responsibility. If you find any content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending an email) to report violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.