English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Lösungsmethode für das Problem, dass die Splash-Schnittstelle von Android weiß oder schwarz wird

前言

我相信很多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 know the why as well as the how, I hope that students can continue to analyze with me the reasons for the white screen.

The window launch process of the Activity component

Firstly, it is declared that a large amount of content in this section has been referenced from the blog of teacher Luo Shengyang. 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 launch process of the Activity component. During the launch process of the Activity component, it 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 launch 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 launch window for the Activity component that is being launched. If necessary, the ActivityManagerService service will request the WindowManagerService service to set a launch window for the Activity component that is being launched (ps: this launch 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;
 }
 // Die Aktivität in den Historienstack einlegen und fortfahren
 mHistory.add(addPos, r);
 if (NH > 0) {
  // Wir möchten, dass das Startvorschaufenster angezeigt wird, wenn wir
  // Wechsel zu einer neuen Aufgabe oder der Prozess des nächsten Aktivitäten ist
  // nicht derzeit laufend.
  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;
  }
 }
 }
}

Zu einem späteren Zeitpunkt fortgesetzt ... Wir hoffen, dass alle weiterhin aufmerksam zusehen.

Das ist der gesamte Inhalt dieses Artikels. Wir hoffen, dass er Ihnen bei Ihrem Lernen hilft und dass Sie die Unterstützung und Unterstützung des Lernens schreien.

Erklärung: Der Inhalt dieses Artikels wurde aus dem Internet entnommen und gehört den jeweiligen Urhebern. Der Inhalt wurde von Internetnutzern selbstständig beigesteuert und hochgeladen. Diese Website besitzt keine Eigentumsrechte und hat den Inhalt nicht von Hand bearbeitet. Diese Website übernimmt keine Haftung für rechtswidrige Inhalte. Wenn Sie rechtswidrige Inhalte finden, senden Sie bitte eine E-Mail an: notice#oldtoolbag.com (Bitte ersetzen Sie # durch @ beim Senden von E-Mails zur Meldung von Verstößen und fügen Sie relevante Beweise bei. Bei nachgewiesener Rechtsverletzung wird diese Seite sofort den beanstandeten Inhalt löschen.)

Empfohlene Artikel