Android 12 Splash Screen API兼容问题:部分低版本设备闪屏后出白屏
闪屏页(SplashScreen)部分设备显示白屏问题
我实现了一个独立的SplashScreen Activity,在该页面中执行一次性的全局API调用、SDK初始化、Firebase RemoteConfig默认值配置以及页面路由逻辑。该功能在部分设备上运行正常,但在部分设备上显示闪屏后会出现白屏现象。
测试设备列表
- Samsung S20 FE(Android 12)- 运行正常
- OnePlus(Android 11)- 运行正常
- MI(Android 11)- 出现白屏
- Moto G5 Plus(Android 8)- 出现白屏
注:上述业务逻辑处理耗时较短,日志如下:
2022-11-01 15:24:13.146 5905-5905 V OnCreate 2022-11-01 15:24:13.177 5905-5905 V SplashScreen.installSplashScreen 2022-11-01 15:24:13.275 5905-5905 V setKeepOnScreenCondition 2022-11-01 15:24:13.282 5905-5905 V onTaskComplete 2022-11-01 15:24:13.297 5905-5905 V nextScreen 2022-11-01 15:24:13.315 5905-5905 V User details is not null in SplashScreen 2022-11-01 15:24:18.716 5905-5905 V onDestroy
Manifest文件配置
<activity android:name=".splashscreen.SplashScreenActivity" android:exported="true" android:label="@string/app_name" android:theme="@style/Theme.App.Starting"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
values/styles配置
<style name="Theme.App.Starting" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/white</item> <item name="windowSplashScreenAnimatedIcon">@drawable/ic_impact</item> <item name="windowSplashScreenAnimationDuration">500</item> <item name="postSplashScreenTheme">@style/AppTheme</item> </style>
values/styles (v31)配置
<style name="Theme.App.Starting" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/white</item> <item name="windowSplashScreenAnimatedIcon">@drawable/ic_impact_anim</item> <item name="windowSplashScreenAnimationDuration">1000</item> <item name="postSplashScreenTheme">@style/AppTheme</item> </style>
SplashScreenActivity核心代码
@Override protected void onCreate(Bundle savedInstanceState) { SplashScreen splashScreen = SplashScreen.installSplashScreen(this); super.onCreate(savedInstanceState); splashScreen.setKeepOnScreenCondition(() -> true); Utils.initThirdPartySdk(); initiateRemoteConfig(); } // 最后调用nextScreen() private void nextScreen() { Timber.v("nextScreen"); boolean userLogin = MainApplication.isUserLoggedIn(); if (userLogin) { Timber.v("User details is not null in SplashScreen"); showMainActivity(); } else { Timber.w("User details is null in SplashScreen, opening LoginActivity"); showLoginActivity(); } finish(); } private void showMainActivity() { Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); }
内容的提问来源于stack exchange,提问作者Shashank Pednekar
相关产品推荐
相关产品推荐

