当应用程序在Android中处于后台时如何显示初始屏幕? [英] How to show splash screen when app is in background in Android?
问题描述
我的应用程序有一个启动画面(无法避免,因为是出于品牌原因).
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).
我应该在MainActivity中为视图覆盖onPause()和onResume()吗?
Should I overide onPause() and onResume() for the view in MainActivity?
清单:
<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>
飞溅活动: 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(): 只显示带有文本和按钮的布局
onCreate():
setContentView(R.layout.example_view);
现在,当我的应用程序处于后台并且当我按菜单按钮查看堆栈中的应用程序列表时,我应该看到splashview(xml文件)而不是默认行为,即MainActivity布局.
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.
我知道所有的iOS银行应用程序都具有此功能.
I know all the iOS Banking application has this feature.
已编辑:
如果您在后台看到twitter应用程序(示例),我想用启动屏幕遮罩应用程序视图.现在使用FLAG_SECURE可以帮助我用白屏遮盖屏幕,但我想显示Splash布局而不是白屏.
- 如果您从iOS设备上看到以下图片-DISCOVER应用程序(示例)使用启动屏幕遮盖了该应用程序,这可以在Android上完成吗?
推荐答案
这可以在Android上完成吗?
Can this be done on Android?
不是直接,AFAIK.
Not directly, AFAIK.
我应该在MainActivity中为视图覆盖onPause()和onResume()吗?
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
这篇关于当应用程序在Android中处于后台时如何显示初始屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!