I have MainActivity and LoginActivity, the MainActivity use Theme.MySplash (which have blue color and app icon).
At the first launch, the SplashScreen display well (with a background and app icon), However, when I restart the MainActivity from LoginActivity, the SplashScreen display without the app icon.
I restart MainActivity instead of back to MainActivity because in my real application, I need to recreate MainActivity
Here is the demo code
style.xml
<style name="Theme.MySplash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#00f</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="postSplashScreenTheme">@style/Theme.AndroidSplashScreen12</item>
</style>
<style name="Theme.AndroidSplashScreen12" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="android:windowBackground">#fff</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>
MainActivity
class MainActivity : AppCompatActivity() {
var keepSplashScreen = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val splashScreen = installSplashScreen()
setContentView(R.layout.activity_main)
splashScreen.setKeepVisibleCondition { keepSplashScreen }
Handler(Looper.getMainLooper()).postDelayed({
keepSplashScreen = false
}, 1500)
findViewById<Button>(R.id.button_login).setOnClickListener {
startActivity(Intent(this@MainActivity, LoginActivity::class.java))
}
}
}
LoginActivity
class LoginActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login2)
findViewById<Button>(R.id.button_start_main).setOnClickListener {
finishAffinity()
startActivity(Intent(this@LoginActivity, MainActivity::class.java))
}
}
}