Is there any way to show splashScreen when app is in the background or switching tabs. In ionic 6?

532 Views Asked by At

I use privacy-screen plugin to hide content when app is in the background, but it shows just gray background. I need to set splashScreen instead. Any suggestions?

I tried splashScreen plugin, but it is not working for me.

2

There are 2 best solutions below

2
Miguel On

I don't know if it's the best way but I think that using Capacitor appStateChange from @capacitor/app (documentation) you could show and hide a screen with your logo when app is in background or foreground.

import { App } from '@capacitor/app';

App.addListener('appStateChange', ({ isActive }) => {
  console.log('App state changed. Is active?', isActive);
  if(!isActive) showLogoScreen();
  else hideLogoScreen();
});

I hope it helps :)

0
Chris.Z On

For iOS, I did it simply in native code: just find the "applicationWillResignActive" method in AppDelegate and insert a view on top of the window.

For Android, sadly I couldn't find a better solution. The "gray background" you described is likely the implementation of Hide screen in 'Recent Apps List', but allow screenshots