如何使活动不被RecentApps覆盖? [英] How to make activity not to be covered by the RecentApps?

查看:198
本文介绍了如何使活动不被RecentApps覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个锁屏应用。
当锁屏活动正在运行,长pressing HOME键或pressing RecentApps键会调出RecentApps屏幕和屏幕锁将被bypassed.Then我如何才能避免这样的事情发生?
任何帮助将是AP preciated。

I am working on a lock screen app. When the lock screen activity is running,long pressing HOME key or pressing RecentApps key will call out the RecentApps screen and the screen lock will be bypassed.Then how can I avoid such thing happening? Any help would be appreciated.

编辑:
感谢所有answers.There必须有不清楚的,我想question.I导航栏上的主场龙pressing或RecentApps关键不是我的活动运行时的工作。

Thanks for all the answers.There must be something unclear in my question.I want HOME long pressing or RecentApps key on navigation bar not to work while my activity is running.

推荐答案

添加此功能,并从你叫的onCreate 你的 MainActivity

Add this function and call it from you onCreate of your MainActivity:

private void setAsLockScreen() {
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG | WindowManager.LayoutParams.FLAG_FULLSCREEN);

    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}

此外,你需要添加:

android:excludeFromRecents="true"

你的清单,以避免显示那里的应用程序。它实际上是不是必需的,但不错的。

to your Manifest to avoid showing the app there. It is actually not required but nice to have.

请注意:如果你想使用多个活动,您的默认锁屏将显示的时间很短的周期内,当活动发生改变。我张贴在这里的解决方案:<一href=\"http://stackoverflow.com/questions/22973884/android-lock-screen-multiple-activities-a-k-a-basic-kiosk-mode\">Android锁屏多项活动(a.k.a基本预设模式)

Note: if you want to use multiple activities, your default lock screen will be shown for a very short period of time when the activities change. I posted a solution for that here: Android lock screen multiple activities (a.k.a basic kiosk mode)

编辑:这种方法提供了一些说明。如果不实现任何功能,留下您的应用程序在此模式下你锁定:)。在这种情况下,你必须远程卸载应用程序。

some additional notes on this approach. If you don't implement any function to leave your app in this mode you're locked :). In this case, you have to uninstall the app remotely.

如果您还添加了&LT;类机器人:名字=android.intent.category.LAUNCHER/&GT; 来的活动,并将其设置为默认启动,它会开机后自动启动,您将无法在家庭或后退挖掘了。近期应用程序可以通过滑动出来的其他应用程序被清除。如果没有其他的应用程序,你不能切换到其他应用:)

If you also add the <category android:name="android.intent.category.LAUNCHER" /> to your Activity and set it to the default launcher, it will start automatically after booting and you won't be able to tap on Home or Back anymore. The Recent App can be cleared by swiping out the other apps. If there are no other apps, you can't switch to other apps :)

这篇关于如何使活动不被RecentApps覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆