I have searched the stackoverflow for this question and found : Android, Detect when other apps are launched and Reliable way to detect application launch from home / desktop?
Android default recent apps dialog implementation is best reference for you, look here..check reloadButtons()
final ActivityManager am = (ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RecentTaskInfo> recentTasks =
am.getRecentTasks(MAX_RECENT_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
You can try in similar way..