Hiding content when the app isn't active


I need our app to hide its content with a splash screen when the app isn’t directly active, ie. when f.x you double tab on the home button on IOS and it shows all the active apps.

I tried using the example code from here:

But it seems like the BackgroundTask.beforeExit function isn’t called before the app is entirely in the background, which at that time it too late.

Any clues or pointers on how to achieve the wanted effect is greatly appreciated.


Answering my own question here - might be helpfull for others:

For Android it is not really possible to hide it with the Splashscreen, but you can hide the content with a solid colored background by adding this to your MainActivity.java file:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

For IOS:
WIP :slight_smile:

Follow up on the IOS part.

To hide the content when multi task switching between apps, either hide or add a splash screen image in the AppDelegate.swift files applicationWillResignActive function:

 func applicationWillResignActive(_ application: UIApplication) {
    self.window?.isHidden = true;

And make it visible again in the applicationDidBecomeActive function:

 func applicationDidBecomeActive(_ application: UIApplication) {
    self.window?.isHidden = false;

Hopefully Ionic/Capacitor will add this kind of functionality to the SplashScreen plugin or provide it in another way.

This improvement suggestion would be nice: