简体   繁体   English

Android主页按钮禁用应用程序展示

[英]Android Home button disable application exhibition

I'm developing an application for a museum, I need that application to be the only one the visitors can use. 我正在为博物馆开发一个应用程序,我需要该应用程序是访客可以使用的唯一应用程序。

The administrator of the museum has the possibility to quit this application, by a button, which will ask a password. 博物馆的管理员可以通过一个按钮来退出此应用程序,该按钮将要求输入密码。

I already managed to override the return button. 我已经设法覆盖返回按钮。 But the Home button is still active. 但是“主页”按钮仍处于活动状态。 I used this for my main activity: 我将其用于主要活动:

<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> 

This will reload the main activity when the home button is pressed. 当按下主页按钮时,这将重新加载主要活动。 But, when I try to close the application with my close button, the first instance of my application is closed but not the second one. 但是,当我尝试使用关闭按钮关闭应用程序时,我的应用程序的第一个实例关闭了,但第二个实例却没有关闭。 The admin has to give the password again. 管理员必须再次输入密码。

You can imagine if a user presses the home button 10 times, it will be very difficult for the admin to quit. 您可以想象,如果用户按下主屏幕按钮10次,管理员将很难退出。

Is there a way to close all instances of my application at the same time? 有没有办法同时关闭我的应用程序的所有实例?

when I try to close the application with my close button, the first instance of my application is closed but not the second one 当我尝试使用关闭按钮关闭应用程序时,我的应用程序的第一个实例已关闭,但第二个实例却未关闭

there is only one instance of your Application , and two or more instances of your main Activity . 您的Application只有一个实例,而主Activity只有两个或多个实例。

I guess you know the difference between activity and application, but I think it's important to mention it... 我想您知道活动和应用程序之间的区别,但是我认为必须提一下...

you can avoid adding to the activity stack additional instances of the same activity by providing in the manifest to the activity's element launch mode attribute. 您可以通过在清单中提供活动的元素启动模式属性,来避免将同一活动的其他实例添加到活动堆栈中。

for example, providing android:launchMode="singleInstance" according to the documentation, insures only one instance of your activity can be created. 例如,根据文档提供android:launchMode="singleInstance" ,可确保只能创建活动的一个实例。 trying starting same activity on top of already existing one - will simply won't change anything in the activity stack, but just invoke the onNewIntent() activity callback on the already existing activity instance. 尝试在已存在的活动实例之上开始相同的活动-只会更改活动堆栈中的任何内容,而只是在已存在的活动实例上调用onNewIntent()活动回调。

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

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