Android的活动管理 [英] Android activity manager

查看:146
本文介绍了Android的活动管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,我有一个通用的逻辑问题。我想15后注销用户如果没有活动。如何找到在Android中的任何活动。我应该怎么做呢?

I guess, I have a generic logic problem. I want to logout a user after 15 if there is no activity. How do I find any "activity" in android. How should I go about it...

专家请帮助...

推荐答案

您需要多花点心思投入到您的要求在这里到底是什么,但我可以告诉你要跟踪的用户交互如果自上次交互的期限届满,执行一些动作,你的情况登录到你的应用程序。

You'll need to invest a little thought into exactly what your requirements are here, but from what I can tell, you want to keep track of the user interactions and if a time limit expires since the last interaction, perform some action, in your case logging them out of your application.

首先,你需要一些地方,你可以跟踪当最​​后的互动发生,因为你会想这是应用广泛,你可以使用的持有本,或<一href="http://www.jameselsey.co.uk/blogs/techblog/android-implementing-global-state-share-data-between-activities-and-across-your-application/"相对=nofollow>重写应用程序类,无论哪种方式应该做的。

Firstly, you'll need some place that you can track when the last interaction occured, since you'll want this to be application wide you could use a singleton to hold this, or override the Application class, either way should do.

接下来,你需要开始跟踪用户交互。从你的活动,您可以覆盖 onUserInteraction 方法,这得到随时用户与应用程序进行交互,如键事件调用。每当你打这个方法,更新你的单,让它知道事情已经发生了,一个时间戳。

Next, you'll need to start tracking user interactions. From your activities, you can override the onUserInteraction method, this gets invoked anytime the user interacts with the application such as key event. Each time you hit this method, update your singleton and let it know something has happened, with a timestamp.

最后,你需要某种形式的循环检查,经常检查,如果有任何事情最近发生的。那里有各种各样的是这样做的,你可以有一个不断循环的,目前比较时间戳到最后记录的事件,有点草案code:

Finally, you'll need some kind of looping check to constantly check if anything has happened recently. Theres various was of doing this, you could have a continuous loop that compares current timestamp to the last recorded event, a bit of draft code :

while(true)
{
   if (timeLastEventRecorded < (now - 15))
   {
      //nothing has happened in 15 minutes, so take corrective action
   }
}

presumably你已经有一些code。在您的应用程序负责注销的,当用户点击退出,你应该能够调用样品上面,如

Presumably you'll already have some code in your application that takes care of logouts, such as when the user clicks "logout", you should just be able to invoke that in the sample above.

希望这有助于

这篇关于Android的活动管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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