开发者

How to be notified when an activity is launched

开发者 https://www.devze.com 2023-02-03 13:33 出处:网络
I want to implement something that does/check some things every time an activity (or application) is lunched and goes in the foreground.

I want to implement something that does/check some things every time an activity (or application) is lunched and goes in the foreground.

Something similar to those Application Protection solutions that you use to protect any installed applications on your phone and they intercept when an application is lunched and prompt you with a password, PIN, etc.. (example : http://www.appbrain.com/app/app-protector-pro/com.carrotapp.protectpronew)

I believe that this is the mechanism I need and those protection a开发者_Go百科pplications use, they have a running service and somehow (this is what I'm interested) the are notified when an application is lunched . I believe that the service from these application just poll every second what is running, this would be a big battery usage, they have somehow to be notified when this happens.

So my question is how this can be achieved?


You can use a BroadcastReceiever to be notified when a package is ADDED, REMOVED, RESTARTED, and so on. And there is the category LAUNCHER there, but I don't think there is any way to just be notified when every application or Activity starts (that seems excessive anyway, which is probably why there isn't such a way), though you might be able to parse the log as Alex suggests.

For reference, see this question: Registering my broadcast receiver to run when an app is launched?

0

精彩评论

暂无评论...
验证码 换一张
取 消