Android中应用程序处于后台时如何显示启动画面?

时间:2017-04-05 18:11:45

标签: android android-intent android-activity splash-screen

我的应用程序中有一个启动画面(无法避免,因为它是出于品牌推广的原因)。

我想屏蔽用户界面并在后台显示启动画面(如银行应用程序)。

我应该在MainActivity中覆盖onPause()和onResume()吗?

清单:

<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布局。

我试过的其中一件事是添加

getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                WindowManager.LayoutParams.FLAG_SECURE); 

使用白色屏幕在背景中屏蔽应用程序,但我在应用程序处于后台时尝试显示启动视图。

我知道所有iOS Banking应用程序都有此功能。

已修改enter image description here

如果您在后台看到Twitter应用(示例),我想用启动画面屏蔽应用程序视图。现在使用FLAG_SECURE帮我用白屏屏蔽屏幕,但我想显示Splash布局而不是白屏。

  • 如果您从iOS设备上看到以下图片 - DISCOVER应用程序(示例)使用初始屏幕屏蔽应用程序,这可以在Android上完成吗

enter image description here

1 个答案:

答案 0 :(得分:2)

  

这可以在Android上完成吗?

不直接,AFAIK。

  

我应该在MainActivity中覆盖onPause()和onResume()吗?

可能不是。欢迎您在那里更改您的用户界面:

  • 出于其他原因调用这些方法(例如,当用户在多窗口模式下点击另一个窗口时,当您启动另一个活动时)

  • 截至拍摄截图时可能为时已晚