英文:
Splash screen api not working on android 12 (API 31, 32)
问题
我看过关于这个问题的不同帖子,还在Google的问题跟踪器上看到一个开放的问题,他们说这不是一个错误,而是有意为之的行为。 https://issuetracker.google.com/issues/197906327
尽管很多人说它没有按照预期工作。
如果你从设置 -> 应用程序 -> 我的应用程序中打开应用程序,然后
splashScreen.setOnExitAnimationListener
会被多次调用,启动画面显示但没有图标,然后应用程序卡在一个空白屏幕上。在API 31上也是同样的情况,但在这里
splashScreen.setOnExitAnimationListener
根本不会被调用,应用程序仍然卡在空白屏幕上。
是否有解决这个问题的方法?或者有没有可以让它工作的方法?
在所有其他API上都可以工作,但在31和32上不行。
英文:
I've seen different posts about this, and also an open issue on google where they say it's not a bug, but intended behaviour instead. https://issuetracker.google.com/issues/197906327
Although a lot of people say it's not working as intended.
If you open the app from settings -> apps -> myApp then
splashScreen.setOnExitAnimationListener
gets called a lot of times, the splash screen is shown without the icon, and then the app gets stuck at a blank screen. The same happens with API 31 but here
splashScreen.setOnExitAnimationListener
doesn't get called at all and is still stuck on the blank screen.
Is there any fix for this? or hack to make it work?
On all other API's it works but not 31 and 32.
答案1
得分: 1
Jetpack (androidx) > Core
问题 197906327 中的问题:“在调试模式下使用 CustomSplashScreen
时未调用 splashScreen.setOnExitAnimationListener()
” 似乎没有任何修复,只有(不完美的)解决方法。
-
要么将您的主题的 windowBackground 属性 设置为纯色。这将阻止系统显示默认的启动画面,而会显示您的自定义启动画面。
另请参阅 "将现有的启动画面实现迁移到 Android 12 及更高版本"。 -
要么使用
setOnExitAnimationListener()
方法 监听启动画面被解散时的情况。
关于最后一种选项:
问题在于在调试模式下使用 CustomSplashScreen
类时未调用 setOnExitAnimationListener()
方法。这是因为在调试模式下实际上并未显示 CustomSplashScreen
类。相反,系统会显示默认的启动画面。
但是,如果您使用 setOnExitAnimationListener()
方法,当 默认 启动画面被解散时仍然会调用监听器。这是因为监听器附加到了 SplashScreen
接口,该接口由 CustomSplashScreen
类和默认启动画面都实现。
因此,尽管在调试模式下使用 CustomSplashScreen
类时未调用 setOnExitAnimationListener()
方法,但在默认启动画面被解散时仍将调用该方法。这意味着您可以使用监听器来启动您的应用程序的主活动,即使在调试模式下也可以。
例如,以下代码会使用 setOnExitAnimationListener()
方法在调试模式下启动您的应用程序的主活动:
val splashScreen = installSplashScreen()
splashScreen.setOnExitAnimationListener {
// 在此处启动您的应用程序的主活动。
startActivity(Intent(this, MainActivity::class.java))
}
英文:
The Jetpack (androidx) > Core
issue 197906327: "splashScreen.setOnExitAnimationListener()
not called when using CustomSplashScreen
in debug mode" does not seem to have any fix, only (imperfect) workarounds.
-
Either setting the windowBackground property of your theme to a solid color. That will prevent the system from displaying the default splash screen, and your custom splash screen will be displayed instead.
See also "Migrate your existing splash screen implementation to Android 12 and higher" -
Or using the
setOnExitAnimationListener()
method to listen for when the splash screen is dismissed.
On that last option:
The issue is that the setOnExitAnimationListener()
method is not called when using the CustomSplashScreen
class in debug mode. That is because the CustomSplashScreen
class is not actually displayed in debug mode. Instead, the system displays the default splash screen.
However, if you use the setOnExitAnimationListener()
method, the listener will still be called when the default splash screen is dismissed. That is because the listener is attached to the SplashScreen
interface, which is implemented by both the CustomSplashScreen
class and the default splash screen.
So, even though the setOnExitAnimationListener()
method is not called when using the CustomSplashScreen
class in debug mode, it will still be called when the default splash screen is dismissed. That means that you can use the listener to start your app's main activity, even in debug mode.
For instance, this would use the setOnExitAnimationListener()
method to start your app's main activity in debug mode:
val splashScreen = installSplashScreen()
splashScreen.setOnExitAnimationListener {
// Start your app's main activity here.
startActivity(Intent(this, MainActivity::class.java))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论