Android release only displays splash screen on the first launch

Hi everybody,

I just released an android version of my app, and the splash screen only shows at the first launch of the app. It doesn’t show at the next launches.

I made a release using:
$ ionic package build android --release --profile profile_production

config.xml:

<preference name="SplashScreen" value="screen"/>
<preference name="AutoHideSplashScreen" value="false"/>
<preference name="orientation" value="portrait"/>
<preference name="SplashScreenDelay" value="5000"/>

<platform name="android">
 <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
 <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
 <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
 <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
 <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
 <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
 <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
 <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
 <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
 <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
 <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
 <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
</platform>

This could be because the app is not terminated, but still running in the background. So, if you click the app icon, the running instance is brought to the foreground.

1 Like

Hi LouisR, I use the exact code from the above but it is for ios. I think the “SplashScreenDelay”'s value is too high, if my memory serves me right I tried to give it a large value and it caused the app to crash or stop.

value <= 3000 is the value it works.

Give it try and see.

@arjenbroeze indeed you are right. On Android, if I just tap the ‘back’ button, the app is not really terminated.
How can I make it so ?
Thanks

@KimB
I saw somewhere in the forum that it was recommended to use a long delay : <preference name="SplashScreenDelay" value="10000"/>
and to hide the splash screen manually with: $cordovaSplashscreen.hide();

1 Like

I think the default behaviour of IONIC is to close the app if the back button is pressed and you’re at the beginning of the view history. Is there something in your code maybe that prevents this from happening?

No there is nothing in my app that could prevent it I think. I only hack the back button on modals:

$ionicModal.fromTemplateUrl('templates/modalProfile.html', {
                scope: $scope,
                hardwareBackButtonClose: false
...

Currently not much time, but on Android it is possible to close the application explicitly by using “navigator.app.exitApp()”. You can either put this behind a button in your app, or hack the back button in the “ready” event. If you need an example, just let me know.

I would like the back button to have the expected normal behavior : back in history or close the app at the end of history…

You could add something like this in your .run function in app.js (typing from the top of my head, code might contain some typos):

.run(function($ionicPlatform, $ionicHistory) {
    $ionicPlatform.ready(function() {
        if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            cordova.plugins.Keyboard.disableScroll(true);
        }
    }
    $ionicPlatform.registerBackButtonAction(function(e) {
       if ($ionicHistory.backView==null)
           navigator.app.exitApp();
       else
          $ionicHistory.goBack();
        e.preventDefault();
        return false;
    }, 999);
});

ok good idea, thanks.

Do you think it will still preserve the behavior I set for the modals like mentioned above ?

Don’t know. Will check when I get home.

The above code does interfere with other back behaviour I used. Here is the code I use to change the behaviour depending upon the current view:

// Change the behaviour of the Back button
$ionicPlatform.registerBackButtonAction(function (event) {
    switch($state.current.name) {
        case "tabs.home":
            navigator.app.exitApp();
            break;

        case "tabs.charts":
        case "tabs.sessions":
        case "tabs.analytics":
            event.preventDefault();
            break;

        default:
            navigator.app.backHistory();
    }
}, 100);

I may have been hasty when I stated “The above code does interfere with other back behaviour”. Testing shows it seems to work but I still prefer the code from my last comment. Interestingly, I still have the problem where I only get the splash on first launch. If I close the app using the Android Recent Apps list, the splash does show on the next launch.
navigator.app.exitApp() does not seem to completely remove the app from memory. Is there an ionic command to completely “terminate” the app?

I think that

<preference name="SplashShowOnlyFirstTime" value="false" />

will fix your problem.