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 has been bothering you should have disappeared. In order to know why it is so, and to know why it is so, I hope that the students can continue to analyze with me the reasons for the white screen.
The window launch process of the Activity component
First of all, it is declared that this section of content has referred to a large number of Lu 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 trace 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, 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(メール送信時は、#を@に変更してください)で通報し、関連証拠を提供してください。一旦確認がとりついたら、本サイトは侵害された内容をすぐに削除します。