[android] Determining the current foreground application from a background task or service

The ActivityManager class is the appropriate tool to see which processes are running.

To run in the background, you typically want to use a Service.