How to be notified when foreground (top) activity (application) changes
AFAIK there are two ways to do that.
You should bind every activity to the service and you will know which activity is running.
try this:
List runningTaskInfos=actvityManager.getRunningTasks(1).get(i).topActivity .getPackageName();
this method will give info of activity's package name which is in foreground..............