机器人自动注销,当应用程序被切换到后台 [英] Android auto-logout when app goes to background

查看:222
本文介绍了机器人自动注销,当应用程序被切换到后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

欲检测时我的应用程序发送给的背景。大约有挂钩HOME键的许多问题 - 我知道这是可能只有在注册为启动应用程序

I want to detect when my application is sent to the background. There are many questions about hooking the HOME key - I understand this is possible only by registering as a launcher app.

...但是...一如既往有一个客户端谁想要某种行为......

...BUT... as always there is a client who wants certain behaviour...

我们有安全性要求高的应用程序。客户希望应用程序注销服务器每当应用程序进入后台无论出于何种原因(电话,HOME键,返回上最后一项活动)( *的澄清我的意思是,当正面在屏幕上的活动是不是对我的应用程序的活动之一, * 的*)。

We have an app with high security requirements. The client wants the app to log out of the server whenever the app goes into the background for whatever reason (phone call, HOME key, back on last activity) (* *to clarify I mean that when the front Activity on the screen is not one of my app's activities **).

所以,如果我不能勾HOME键,还有什么其他选择吗?明明只是挂钩的onPause()也无济于事,因为这是活动特异性。

So, if I can't hook the HOME key, what other options are there? Obviously just hooking onPause() won't help, because that is Activity-specific.

最佳,我们想出了是要保持活性引用数组在我们的应用程序类。在每个活动的 onResume(),我们将它添加到这个数组。在的onPause()我们将其删除。此外,在的onPause()我们通过这个数组枚举,以找出是否有任何注册的活动是在前台。如果没有前台活动被发现,用户被注销。

The "best" we have come up with is to keep an array of Activity references in our Application class. In each Activity's onResume() we add it to this array. In onPause() we remove it. Also in onPause() we enumerate through this array to find out if any of the registered activities are in the foreground. If no foreground activity is found, user gets logged out.

我很不满,这是一个解决方案,并希望找到一个更好的办法。

I am unhappy with this as a solution, and hope to find a better way.

推荐答案

我们eneded了基于解决方案,这里由@peceps去的东西:的当Android应用程序被关闭/发送到后台运行code。

We eneded up going for something based on solution here by @peceps: Run code when Android app is closed/sent to background.

这篇关于机器人自动注销,当应用程序被切换到后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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