如何测试活动不活动时间

发布于 2024-09-25 02:29:55 字数 307 浏览 1 评论 0原文

我想知道为了了解用户何时与我的应用程序交互,我可以达到的最高级别是什么

:我想在用户不活动 X 秒后注销我的应用程序。 所以我所做的是创建一个带有计时器的服务,以及一个将计时器重置为 X 时间的切换函数。 X时间过去后,提出意图,广播接收器捕获该意图并执行注销(也关闭打开的登录活动...)

至于实际问题,我需要调用“计时器切换”每次用户与应用程序交互时都会运行。 当用户与手机交互时,我可以知道的android应用程序中最高的位置在哪里

我发现的唯一的就是为每个活动实现onClick和onKeyPress,还有其他更好的方法吗?也许在应用程序类中?

I'm wondering what is the highest level I can go in-order to know when the user interacts with my application

preface: I'd like to logout of my application after X seconds of user inactivity.
so what I did is create a service with a timer, and a toggle function which resets the timer to X time.
after X time has passed, an intent is raised, and a broadcast receiver catches that intent and preforms the logout (closing the open logged in activities as well...)

as for the actual question, I need to call the "Timer Toggle" function each time the user interacts with the application.
where is the highest place in the android app that I can know when the user interacts with the phone

The only thing I found is to implement onClick and onKeyPress for each activity, is there another better way? maybe in the Application class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灰色世界里的红玫瑰 2024-10-02 02:29:55

我认为除了从 Activity 本身发送事件之外,没有其他方法。
您可以查看覆盖 Activity.onUserInteraction()

但用户是否可能会在应用程序的单个 Activity 中停留“X 秒”,而不会切换屏幕或让设备进入睡眠状态?

我想在 onCreate、onPause 和 onResume 中更新计时器/标志就足够了。另外可能还有 Activity 中的一些常用函数。

I don't think there's any other way aside from sending events from the Activity itself.
You could look at overriding Activity.onUserInteraction().

But is it likely that the user will be in a single Activity of your application for "X seconds" without ever switching screens, or letting the device go into sleep?

I imagine it would be sufficient to update the timer/flag in onCreate, onPause and onResume. Plus maybe some commonly-called functions within the Activity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文