【发布时间】:2022-01-19 10:08:03
【问题描述】:
我们需要设计用于识别用户是否登录?这意味着我们需要设计一个路由来决定我们需要在启动屏幕之后显示哪个Activity。我们如何为此编写代码。当我们将 SplashActivity 编写为路由时,它会出现白屏并变得比其他应用程序慢。非常感谢
【问题讨论】:
标签: android splash-screen
我们需要设计用于识别用户是否登录?这意味着我们需要设计一个路由来决定我们需要在启动屏幕之后显示哪个Activity。我们如何为此编写代码。当我们将 SplashActivity 编写为路由时,它会出现白屏并变得比其他应用程序慢。非常感谢
【问题讨论】:
标签: android splash-screen
您的问题在官方文档中有答案。请看https://developer.android.com/guide/topics/ui/splash-screen/migrate
可以通过以下方式实现:
//let's imagine this is your SplashScreen, the starting point of the app
class RoutingActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
// Keep the splash screen visible for this Activity
// it means that there will be only your splash screen visible
// since we don't set "setContentView(resId : Int)"
splashScreen.setKeepOnScreenCondition { true }
//after you've checked if user is logged in, show the other activity
startSomeNextActivity()
finish()
}
...
【讨论】: