简体   繁体   English

禁止从android应用程序android 4.0+逃脱

[英]Disable escape from android app android 4.0+

I am developing application that should start one application and user cannot close that application or leave it. 我正在开发应启动一个应用程序且用户无法关闭或离开该应用程序的应用程序。 So I need to disable all 3x buttons (Back, Home, Multitask). 因此,我需要禁用所有3x按钮(“上一步”,“主页”,“多任务”)。 Disable of back button is easy only override methon onBackPressed(). 禁用后退按钮很容易,只需覆盖methon onBackPressed()。 But how can i disable Home and Multitask. 但是我如何禁用Home和Multitask。 I read that override of Home button is not possible in 4.0+ android so how can i do it? 我读到4.0 + android中无法覆盖“主页”按钮,所以我该怎么办? And can i block Multitask button so user cannot escape from Application? 我是否可以阻止多任务按钮,使用户无法从应用程序中退出?

PS: This application will never be released on Android Market so solution can be againts "rules". PS:此应用程序永远不会在Android Market上发布,因此解决方案可以再次成为“规则”。

BackButton 返回键

http://developer.android.com/guide/components/tasks-and-back-stack.html http://developer.android.com/guide/components/tasks-and-back-stack.html

Suppose you are in activity A you navigate to B and then to C. In Activity C you press back button, activity C is popped from the stack, destroyed and the previous activity which is B is displayed 假设您在活动A中,先导航到B,然后导航到C。在活动C中,按返回按钮,活动C从堆栈中弹出,销毁,并显示上一个活动B

Suppose you wish to navigate to A from C then you can override back button pressed 假设您希望从C导航到A,那么您可以覆盖按下的后退按钮

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) { 
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
}

return super.onKeyDown(keyCode, event);
}

public void onBackPressed() {
Intent myIntent = new Intent(C.this, A.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // clear back stack 
startActivity(myIntent); 
finish(); 
return;
}

HomeButton 主页按钮

There is no way to intercept the home button on Android, unless you make your app the home screen. 除非您将应用设为主屏幕,否则无法拦截Android上的主屏幕按钮。 This is for security reasons, so that malicious apps cannot take over your device by overriding all the buttons that can exit. 这是出于安全原因,因此恶意应用无法通过覆盖所有可以退出的按钮来接管您的设备。 The home button is the one sure shot way to be able to leave any app. 主页按钮是一种可以离开任何应用程序的确定方法。

If you want to handle the HOME button, implement a home screen. 如果要处理HOME按钮,请实现主屏幕。 You cannot disable a home button. 您不能禁用主页按钮。

android:launchMode ="standard|singleTop|singleTask |singleInstance" android:launchMode =“ standard | singleTop | singleTask | singleInstance”

Check the activity launchmode @ http://developer.android.com/guide/topics/manifest/activity-element.html#lmode for singleInstance. 检查活动启动模式@ http://developer.android.com/guide/topics/manifest/activity-element.html#lmode中的singleInstance。 the device can hold only one instance of the activity at a time — only one such task. 该设备一次只能保存一个活动实例,而只能执行一个这样的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM