如何在前台(顶部)活动(应用程序)发生变化时收到通知 [英] How to be notified when foreground (top) activity (application) changes

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

问题描述

我想为Android平台编写一个服务,当当前前台活动发生变化时通知.基本上,只有当顶级活动发生变化时,服务才应该执行一些任务.有没有办法订阅并在发生此类事件时收到通知?或者没有可能,服务应该不时轮询正在运行的活动列表并检查前台活动是什么?不是更好的解决方案...

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. 使用无障碍服务,您可以在此处
  3. 找到解决方案
  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天全站免登陆