X分钟后自动注销,安卓 [英] Auto logout after X minutes, Android

查看:208
本文介绍了X分钟后自动注销,安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待实现一个功能,注销闲置X分钟后的用户。在经历上这么相似的答案,建议的方法似乎是 -

  • 在后台运行的计时器。它安排x分钟后超时。
  • 在每一个地方的用户提供应用程序(基本上所有的事件处理程序)进行交互的功能,称之为复位定时器的方法。

我想不出有什么比这更好的自己,但它似乎是一个巨大的痛苦,即使是中等大小的应用程序具有6-7不同的屏幕和一大堆的UI组件。有没有更好的方式来处理呢?

谢谢,
Teja公司。

解决方案
  

在后台运行的计时器。它安排x分钟后超时。

没有,是的。使用一个计时器,如果你实现它在 服务 或在 IntentService 。否则,不。

  

在每一个地方的用户提供应用程序(基本上所有的事件处理程序)进行交互的功能,称之为复位定时器的方法。

这解决办法是很难维持的。

您应该有一个 IntentService (展示品的>)中,可以很容易实现的 的TimerTask 或的 处理程序 ,使里面的可运行code类火灾广播到你的活动。在你的活动,你可以轻松地添加一个 BroadcastReciever 并可以注销用户如果时间超出这种情况下。当你的应用程序是不可见的用户,你就可以开始你的服务。

I'm looking to implement a feature that logs out the user after X minutes of inactivity. After going through a similar answer on SO, the suggested method seems to be to -

  • Have a timer running in the background. Schedule it to timeout after x minutes.
  • In every function where the user interacts with the app (basically all event handlers), call a method that resets the timer.

I can't think of anything better than this myself, but it's seems to be a huge pain even for a medium sized application that has 6-7 different screens and a whole bunch of UI components. Is there a better way to handle this?

Thanks,
Teja.

解决方案

Have a timer running in the background. Schedule it to timeout after x minutes.

No and yes. Use a timer if you're implementing it in a Service or in an IntentService. Otherwise, don't.

In every function where the user interacts with the app (basically all event handlers), call a method that resets the timer.

That solution would be hard to maintain.

You should have an IntentService (demonstrating article here) running in the background that can easily implement a TimerTask or a Handler and make the runnable code inside it fire a broadcast to your activities. In your activities you can easily add a BroadcastReciever and in that case you can log out the user if time is out. You can start your service when your application isn't visible to the user.

这篇关于X分钟后自动注销,安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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