Get notified/receive explicit intents when an activity starts

Posted by qtips on Stack Overflow See other posts from Stack Overflow or by qtips
Published on 2010-03-24T12:23:59Z Indexed on 2010/03/27 0:53 UTC
Read the original article Hit count: 274

Filed under:

Hi,

I am developing an application than gets notified when an activity chosen by a user is started. For this to work, the best approach would be to register a broadcastreceiver for ACTION_MAIN explicit intents, which as far as I know doesn't work (because these intents have specific targets). Another, probably less efficient approach, is to use the system ActivityManager and poll on the getRunningTask() which returns a list of all running tasks at the moment. The polling can be done by a background service. By monitoring the changes in this list, I can see whether an activity is running or not, so that my application can get notified. The downside is ofcourse the polling. I have not tried this yet, but I think that this last approach will probably work.

Does anyone know of a better approach(es) or suggestions which are less intensive?

© Stack Overflow or respective owner

Related posts about android