当前景(上)活动(应用程序)的变化如何被通知 [英] How to be notified when foreground (top) activity (application) changes

查看:97
本文介绍了当前景(上)活动(应用程序)的变化如何被通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写的就是通知当前的前台活动的变化,当Android平台的服务。 基本服务应该做一些任务只有在顶变化。 有没有什么办法来订阅和当这种事件发生时得到通知? 或者有没有可能和服务应经常进行轮询来时正在运行活动的清单,并检查什么是前台活动?不是preferable解决方案...

I want to write a service for Android platform that is notified when the current foreground activity changes. Basically the service should do some tasks only when the top activity changes. Is there any way to subscribe and to be notified when this kind of event occurs ? Or there is no possibility and the service should poll from time to time the list of running activities and to check what is the foreground activity ?Not preferable solution...

推荐答案

AFAIK有两种方法可以做到这一点。

AFAIK there are two ways to do that.

  1. 在启动服务和监控活动堆栈,你可以检查一下这里
  2. 使用的辅助服务,你可以在这里找到一个解决办法
  1. Start a service and monitor the Activity Stack, you might check it here
  2. Use an Accessibility Service, you could find a solution here

这篇关于当前景(上)活动(应用程序)的变化如何被通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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