How to show splash screen when app is in background on Android?
I have a Splash screen (couldn't avoid it, as well as for branding purposes) for my app.
I want to mask the UI and show the splash screen when it is in the background (like banking apps).
Should I override onPause () and onResume () for the view in MainActivity?
manifest:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>
Burst Activity: OnCreate ()
setContentView(R.layout.splash_layout);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
/* Create an Intent that will start the Main-Activity. */
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
MainActivity (): Just show layout with text and buttons
OnCreate ():
setContentView(R.layout.example_view);
Now that my application is in the background and when I click the Menu button to see the list of applications in my stack, I should see a splashview (xml file), not the deafult behavior and layout of the MainActivity.
One of the things I've tried is adding
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
which masks the app when it's in the background with a white screen, but I'm trying to show a popup view when the app is in the background.
I know all iOS Banking apps have this feature.
If you see the Twitter app (Example) in the background, I want to mask the app view with a splash screen. Right now, using FLAG_SECURE helps me to mask the white screen, but I want to show the splash layout, not the white screen.
- If you see the image below from an iOS device - the DISCOVER app (example) masks the splash screen app, can this be done on Android ?
source to share
Can this be done on Android?
Not directly, AFAIK.
Should I override onPause () and onResume () for the view in MainActivity?
Probably not. Although you can change your interface:
-
These methods are called for other reasons (for example, when the user enters another window in multi-window mode, when you start your other activity)
-
It may be too late as to when the picture was taken
source to share