Reputation: 789
I have a Splash screen(Couldn't avoid it, as it is for branding reasons) for my application.
I want to mask the user interface and show the splash screen when it is in background (like banking applications do).
Should I overide 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>
Splash 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 a layout with text and buttons
onCreate():
setContentView(R.layout.example_view);
Now when my application is in background and When I press Menu button to see list of applications in my stack, I should see the splashview(the xml file) not the deafult behaviour i.e MainActivity layout.
One of the things I tried out is adding
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
which does mask the application when it is in background with White Screen but I'm trying to show the splash view when the app is in background.
I know all the iOS Banking application has this feature.
If you see the twitter app(Example) in the background, I want to mask the application view with splash screen. Right now using FLAG_SECURE helps me to mask the screen with white screen but I want to show Splash layout rather than white screen.
Upvotes: 6
Views: 6302
Reputation: 1006674
Can this be done on Android?
Not directly, AFAIK.
Should I overide onPause() and onResume() for the view in MainActivity?
Probably not. While you are welcome to change your UI there:
Those methods get called for other reasons (e.g., when the user taps on another window in multi-window mode, when you launch another of your activities)
That may be too late with respect to when the screenshot is taken
Upvotes: 3