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

Android Splash 인터페이스가 흰색 화면, 검은색 화면이 되는 문제 해결 방법

서론

저는 많은 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 troubled you should have disappeared. To understand both the cause and the reason, I hope that the students can continue to analyze with me the reasons for the occurrence of these white screens.

The window launch process of the Activity component

Firstly, it is declared that this section of content refers extensively to Professor Luo Shengyang's blog. For the sake of convenience, 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, it is necessary to 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 process of launching, 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 launch window for the Activity component that is being launched. If necessary, then 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 top of 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;
  }
 }
 }
}

속속 계속됩니다... 많은 관심을 부탁드립니다.

이것이 이 문서의 전부입니다. 많은 도움이 되었기를 바랍니다. 또한, 많은 지지를 부탁드립니다.呐喊 교육.

선언: 이 문서의 내용은 인터넷에서 가져왔으며, 원작자의 소유물입니다. 내용은 인터넷 사용자가 자발적으로 기여하고 업로드한 것이며, 이 사이트는 소유권을 가지지 않으며, 인공적인 편집 처리를 하지 않았으며, 관련 법적 책임도 부담하지 않습니다. 저작권 위반이 의심되는 내용이 있으시면, notice#w로 이메일을 보내 주시기 바랍니다.3codebox.com(메일을 보내는 경우, #을 @으로 변경하십시오. 신고를 하시고 관련 증거를 제공하십시오. 사실이 확인되면, 이 사이트는 즉시 위반 내용을 삭제합니다.)

추천해요