![](/img/trans.png)
[英]On migrating to SplashScreen API 12 with Single Activity Architecture
[英]SplashScreen api with different opener activity
我剛剛開始使用SplashScreen
api。 我已經刪除了舊的SplashActivity
,並且在setContentView
之前在MainActivity
中調用installSplashScreen()
。
問題是當我使用SplashActivity
(舊方法)時,我有機會選擇打開下一個活動。 然而,有了這個新的SplashScreen
api,我想不出任何方法來擁有同樣的東西。 當應用程序打開時,我已經在MainActivity
中。
問題是我並不總是在 Splash 之后打開MainActivity
,我還有另一個需要在 Splash 之后偶爾打開的活動。
我怎么能那樣做? 有人能指出我正確的方向嗎?
我在 Android 開發人員網站上找到了本指南: 讓啟動畫面在屏幕上停留更長時間
這可用於檢查加載另一個活動的條件,然后加載該活動而不是MainActivity
您可以做的是,在ViewTreeObserver.OnPreDrawListener
的onPreDraw
方法中,您可以像這樣實現它:
@Override
public boolean onPreDraw() {
// Check if other activity than MainActivity is to be loaded:
boolean shouldLoadOtherActivity = /* some condition */;
if (shouldLoadOtherActivity) {
// Create intent here to load OtherActivity
Intent intent = new Intent(this, OtherActivity.class);
startActivity(intent);
finish(); // finish MainActivity
}
content.getViewTreeObserver().removeOnPreDrawListener(this); // remove the listener
return true;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.