简体   繁体   English

阻止用户关闭或最小化Android应用程序

[英]Prevent users from closing or minimizing an android app

I have an android app where the client will be let two tablets for experiments. 我有一个Android应用程序,客户端将让两个平板电脑进行实验。

The question is: Is possible to prevent users from minimizing or closing the app? 问题是:是否可以阻止用户最小化或关闭应用程序? How can I do that? 我怎样才能做到这一点?

Kiosk mode is what you are looking for! Kiosk模式是您正在寻找的! It was introduced in Android 4.2. 它是在Android 4.2中引入的。

To enable kiosk mode, set this in your activity_main.xml : 要启用kiosk模式,请在activity_main.xml设置:

<intent-filter>
<category android:name="android.intent.category.HOME" /> 
</intent-filter>

This question is most likely a dupe of: Develop app run in kiosk mode in android 这个问题很可能是一个骗局: 开发app在android中的kiosk模式下运行

I have tested a way... It is done on a fragment, you can test it yourself to do it from an activity 我已经测试了一种方法......它是在一个片段上完成的,你可以自己测试它来从一个活动中完成它

public void onDestroyView() {
    if(condition) {
        Intent intent = new Intent(getContext(), MainActivity.class);
        startActivity(intent);
    }
    super.onDestroyView();
}

This is done from an activity B with a fragment on it, then from the main activity, it returns to activity B. With this, the user can't close the app 这是通过活动B完成的,其中包含一个片段,然后从主活动返回到活动B.这样,用户无法关闭应用程序

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

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