1

Dev team I am facing the issue in Android 12 new splash Api. I has followed all the documentation of splash screen that's provided by Android "https://developer.android.com/develop/ui/views/launch/splash-screen". But when we install my app in android 12, icon in splash screen is not showing only background colour is showing. and we close the app and again we open this app icon is showing.

I have attach my code here and screen recording video link.

Manifest Activity

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.Android12Migrations">

    <activity
        android:name=".views.MainActivity"
        android:exported="true"
        android:screenOrientation="portrait"
        android:theme="@style/SplashScreenTheme">

style.xml

 <style name="SplashScreenTheme" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/teal_200</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_app_logo</item>
    <item name="postSplashScreenTheme">@style/AppTheme</item>
</style>

v31styl.xml

<style name="SplashScreenTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/green</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_app_logo</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>

MainActivity

class MainActivity : AppCompatActivity() {

private val alarmManager by lazy { getSystemService(Context.ALARM_SERVICE) as AlarmManager }

private val splashViewModel : SplashViewModel by viewModels()

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

    val mainView = findViewById<View>(android.R.id.content)
    mainView.viewTreeObserver.addOnPreDrawListener(
        object : ViewTreeObserver.OnPreDrawListener{
            override fun onPreDraw(): Boolean {
                //maybe checking locale or making some api to fetch some details
                if(splashViewModel.isDataLoaded.value == true){
                    mainView.viewTreeObserver.removeOnPreDrawListener(this)
                }
                return false
            }

        }
    )

}

SplashViewModel

class SplashViewModel : ViewModel() {

private val _isDataLoaded = MutableLiveData(false) val isDataLoaded: LiveData = _isDataLoaded

init { viewModelScope.launch {

  delay(5000)
  _isDataLoaded.value = true
}

} }

Video link https://drive.google.com/file/d/1LO_LCnnkQZdJ7DX_DYnHbGRfw_OrGZyc/view?usp=sharing

  • The logo only shows when you open the app from launcher. Logo does not show when it is run through android Studio. Here is the [detailed answer](https://stackoverflow.com/questions/69812590/android-12-splash-screen-icon-not-displaying). This has been logged as a bug Which you can track [here](https://issuetracker.google.com/issues/205021357) – Malik Saifullah Sep 28 '22 at 13:00

0 Answers0