如何检测,如果目前家庭活动是ActivityStack顶部目前、家庭、ActivityStack

2023-09-12 05:06:42 作者:谁是你的软肋

我要检测当前的前景活动从后台服务。

I want to detect current foreground activity from a background service.

我特别想知道,如果目前家庭活动是在Android活动堆栈的顶部与否。

Particularly I want to know if Home activity is currently on the top of android activity stack or not.

使用的情况是这样的:如果家庭活动是在前台(即用户没有使用任何其他应用程序),我需要显示在后台服务的一些事件警告对话框。但是,如果家庭的活动是不是在堆栈顶部(即用户使用其他应用程序),我应该显示状态栏的通知上的服务的一些事件。

Use case is something like: If home activity is on foreground (i.e User is not using any other application) I need to show a alert dialog on some event in background service. But if, Home activity is not on top of stack (i.e. user is using some other application), i am supposed to show a notification in status bar on some event in service.

有什么方法来检测当前的前台活动?

Is there any way to detect current foreground activity?

推荐答案

请参阅本 这里

在这里您可以找到前台的活动,然后与家庭package.Its比较其包可能是android.home

Here you can find the foreground Activity then compare its package with the home package.Its may be android.home