2
0

More than 1 year has passed since last update.

Android 12でCaused by java.lang.IllegalStateException You need to use a Theme.AppCompat theme (or descendant) with this activity.

Posted at

概要

AndroidX Core Splashscreenでスプラッシュ画面を作成するとAndroid 12端末で以下のようなクラッシュが発生することがあった。

Caused by java.lang.IllegalStateException You need to use a Theme.AppCompat theme (or descendant) with this activity.

不適切なタイミングでinstallSplashScreen を呼ぶと上記のエラーが発生することがある。

対策

件のクラッシュは 開発者向けオプションアクティビティを保持しないをONにしてアプリをバックグラウンドから起動すると高確率で発生する。

クラッシュの原因は installSplashScreensuper.onCreate の後に呼んでいたため。

MainActivity.kt
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        installSplashScreen()
        ...
    }

installSplashScreensuper.onCreate の前で呼ぶとクラッシュは発生しなくなった。

MainActivity.kt
    override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()

        super.onCreate(savedInstanceState)
        ...
    }

あとがき

公式ドキュメントでは英語だとinstallSplashScreenが先だが、日本語では onCreateが先に書かれているので注意… :crying_cat_face:

英語

スクリーンショット 2022-01-25 13.46.13.png

日本語

スクリーンショット 2022-01-25 13.46.05.png

参考

https://issuetracker.google.com/issues/207095795
https://developer.android.com/guide/topics/ui/splash-screen/migrate#migrate_your_splash_screen_implementation

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0