Question

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 applications 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?

Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top