Hi,
I'm new to Android development and I have to write an app (background, no gui) that should be aware of the running state of some other apps. If one (or more) of the targeted applications are active, my app should be triggered to start doing some things. If they're no longer used, my app should be aware of that too.
For this reason, I'd like to know
how to monitor processes properly on Android, without causing to much overhead and/or battery drain.
So far I've made a little (activity-based) test app that's able to show some information via the ActivityManager-instance:
Code:
List<ActivityManager.RunningAppProcessInfo> procs = activityManager.getRunningAppProcesses();
I could write a service, that starts polling for this information periodically, but I'm afraid this isn't really a good option: it requires quite much processing time and shortens the battery's life time.
I'm looking for alternatives to get this done. Is there any event-based model available, to get notified of changes in the list of running processes without having to poll?
Or is there a possibility to do something with the intents, even though some apps pass their intents explicitly? All applications I'm interested in are doing more or less the same; in this case they respond to "watch video".
Thx for your advice!