Listen to ActivityManager events?

有些话、适合烂在心里 提交于 2019-11-29 12:46:01

I suppose there is no actually other legacy way to handle glabal system state, only

 (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

ActivityManager.getRecentTasks() - Return a list of the tasks that are currently running, with the most recent being first and older ones after in order.

For details check docs

Perhaps though Android is a Linux you can run system tools like

Runtime.getRuntime().exec("ps -aux | grep smth")

But I think it would be hard to detect particular java application.

Golden

I think you can use the launch mode to determine which activity to launch to top level. Please check the question: Android singleTask or singleInstance launch mode?. Maybe it will help you.

dparnas

I had a look in the android source, but there doesn't seem to be any events broadcasted.

https://android.googlesource.com/platform/packages/providers/ApplicationsProvider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!