Basically, I want to find out when another app starts, so I can adjust my app in a particular way. For example, if the user starts the GMail app, my service can detect that and react.
My current idea is to check ‘topActivity’ for each element in getRunningTasks() from the ActivityManager class. But that sounds quite expensive, since it needs to be constantly checking in the background (and I’m quite fussy about the CPU usage of my app).
If anyone knows a better way, I’d love to hear it!
There is not way of doing that the “nice way” meaning a BroadcastListener since applaunch don’t get broadcasted. The only way is to Start a service that checks the
getRunningTasks()(For not to load the CPU too much you can also check what app is to the foreground. I’ll search for the code if you are interested on that technic)
Have the service checking at interval of 5-10 seconds. Also shut down the service at SCREEN_OFF and restart it at SCREEN_ON.
Sorry but there is no other way for that.