安卓空闲时间
我想制作一个应用程序,当它处于“空闲状态”时,它必须停止执行某些操作。当用户在一定秒数(例如 50 秒)内未与应用程序交互时,应用程序将进入空闲状态。是否有一些 android 类用于此或如何以更简单的方式执行此操作?
I want to make an application which when it is on "idle state" it must stop doing something. Application enters in idle when user doesn't interact with the application for a number of seconds (ex. 50). Are there some android classes for this or how to do this in a simpler way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了设备进入睡眠模式之外,Android 中没有内置的“空闲”概念。您可以观看
ACTION_SCREEN_OFF
广播Intents
,但这将适用于整个系统,而不仅仅是您的应用程序。There is no built-in concept of "idle" in Android, other than the device going into sleep mode. You can watch for
ACTION_SCREEN_OFF
broadcastIntents
, but that will be for the whole system, not just your application.如果您没有“后台”任务处理,那么您确实必须了解 Android Activity 生命周期。您不必关心您的应用程序是否“空闲”。您必须始终记住,您的应用程序可以随时被系统置于睡眠状态。
认真阅读仔细阅读开发者指南。
If you have no "background" task processing, you really have to understand the Android Activity lifecycle. You don't have to care about your application going "idle". You have to always keep in mind that your application can be put to sleep by the system AT ANY TIME.
Really read carefully the developer guide.