简体   繁体   English

应用卡在 Android 12(API 级别 31)的启动画面上

[英]App stuck on the Splash screen in Android 12 (API Level 31)

The application is stuck on the splash screen.应用程序卡在启动画面上。 No idea why?不知道为什么? I have done everything the same as the documentation.我所做的一切都与文档相同。 Please look at my code and please tell.请看我的代码,请告诉。

Android Manifest.xml file code: Android Manifest.xml 文件代码:

   <activity
        android:name=".ui.startup.StartupActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

styles.xml code样式.xml 代码

<style name="SplashTheme" parent="Theme.SplashScreen">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/splash</item>
</style>

app.gradle dependency Code: app.gradle 依赖代码:

implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'

StartUpActivity Code:启动活动代码:

 override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    installSplashScreen()
 }

 override fun onStart() {
    super.onStart()
    proceedNavigation()
 }

I have not implemented splash Screen in Android 12 but according to your Code and some document you need to add setConetView and you have to call installSplashScreen() before it.我尚未在 Android 12 中实现启动画面,但根据您的代码和某些文档,您需要添加 setConetView 并且您必须在它之前调用 installSplashScreen()。

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContenView(layout)
}

override fun onStart() {
super.onStart()
proceedNavigation()
} 

Refrence参考

As per this documentation , you must call the installSplashScreen function in your main or launcher activity.根据本文档,您必须在主活动或启动器活动中调用 installSplashScreen 函数。 You must call it before the setContentView.您必须在 setContentView 之前调用它。

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    val splashScreen = installSplashScreen()
    setContentView(R.layout.activity_main)

You should also consider specifying the activity theme to the attribute postSplashScreenTheme so you can have separate themes for your splash screen and application.您还应该考虑为属性 postSplashScreenTheme 指定活动主题,以便您可以为启动画面和应用程序设置单独的主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM