Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: 'Splash screen' only once

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

like image 887
Erik Avatar asked Sep 02 '10 08:09

Erik


People also ask

What is a splash screen in Android?

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

Why am I getting duplicate splash screens on Android 12?

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.

How do I add a splash screen to an 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. --> <!--

How do I use the splashscreen API?

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.


1 Answers

Set android:noHistory="true" to the activity entry at the AndroidManifest.xml. That will prevent the activity from being saved on the stack.

like image 83
Konstantin Burov Avatar answered Nov 04 '22 09:11

Konstantin Burov