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>
After the above configuration, the white screen, black screen, and ActionBar screen that have been bothering you should have disappeared. To understand the cause and effect, I hope that the students can continue to analyze with me the reasons for the generation of these white screens.
The window startup process of the Activity component
Firstly, it is stated that this section of content has referred to Professor Luo Shengyang's blog extensively. For the sake of understanding, the content has been compressed. If there is any infringement, I will delete this analysis immediately.
To understand the root cause of the white screen, one must track 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 checks 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; } } } }
À suivre... espérons que vous continuerez à suivre.
Voici la totalité du contenu de cet article, j'espère qu'il vous sera utile dans vos études, et j'espère que vous soutiendrez également le tutoriel de cri.
Déclaration : le contenu de cet article est extrait du réseau, propriété du propriétaire original, contribué et téléversé par les utilisateurs d'Internet, ce site n'possède pas de propriété, n'a pas été traité par l'édition humaine et n'assume pas de responsabilité juridique. Si vous trouvez du contenu suspect de violation de droits d'auteur, veuillez envoyer un e-mail à : notice#oldtoolbag.com (veuillez remplacer # par @ lors de l'envoi d'un e-mail pour signaler une violation, et fournir des preuves pertinentes. Une fois vérifié, ce site supprimera immédiatement le contenu suspect de violation de droits d'auteur.)