Whenever user open any app i need know if application is running on the UI thread. I also need to show a toast of the Package Name of that application.
I have user Activity Manager but it not working as it should. It always shows displayed Launcher.
ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1);
ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
pack = componentInfo.getPackageName();
Can anyone tell me how I can use usage stats to achieve this?