Android 中的活动/任务更改时如何收到通知
我正在构建一个系统状态记录器。当任何活动/任务进入堆栈并变得对用户可见(不仅仅是我编写的活动/任务)时,我希望收到通知。
ActivityManager 可以计算出顶部的内容: http://developer.android.com/reference/android/app/ActivityManager.html
然而,这需要我经常轮询以重新计算顶部的内容,浪费大量资源。当活动发生变化时,有没有办法接收事件/回调/通知?
** 编辑 ** 需要明确的是,我希望在任何活动成为活动活动时收到通知。
I'm building a system status logger. I'd like to be notified when any activity/task is brought to the stop of the stack and becomes visible by the user (not just the one I wrote).
ActivityManager makes it possible to work out what's on top:
http://developer.android.com/reference/android/app/ActivityManager.html
however, this requires that I frequently poll to recalculate what's on top wasting a lot of resources. Is there a way to receive an event/callback/notification when an activity changes?
** edit ** To be clear -- I want to be notified when any activity becomes the active activity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
onResume() 当 Activity 进入活动状态时被调用。
onResume() is called when activity comes to live state.