I have a Android application that requires a splash screen. I have a simple activity which shows the splash screen and after a number of seconds, it starts the 'main' activity. Now, when a user presses the back button from that activity, the splash screen shows again. How can I prevent this? I tried keeping a boolean shownSplash and this partially works, but when the app is running and the user wants to open it from the app-launcher, the app exits (since splash calls finish() when splashShown is true). Any ideas?
Thanks, Erik
It is a constant screen which appears for a specific amount of time, generally shows for the first time when the app is launched. The Splash screen is used to display some basic introductory information such as the company logo, content, etc just before the app loads completely. Creating Splash screen using handler in Android
If your existing splash screen is implemented using a dedicated Activity , launching your app on devices running Android 12 or higher results in duplicate splash screens: the new system splash screen displays, followed by your existing splash screen activity.
... ... Create a theme with a parent of Theme.SplashScreen, and set the values of postSplashScreenTheme to the theme that the Activity should use and windowSplashScreenAnimatedIcon to a drawable or animated drawable. The other attributes are optional. <!-- Set the splash screen background, animated icon, and animation duration. --> <!--
You can use the SplashScreen API directly, but we strongly recommend using the Androidx SplashScreen compat library instead. The compat library uses the SplashScreen API, enables backward-compatibility, and creates a consistent look and feel for splash screen display across all Android versions. This guide is written using the compat library.
Set android:noHistory="true"
to the activity entry at the AndroidManifest.xml. That will prevent the activity from being saved on the stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With