0

i want to develop an app locker. for that i want recently opened app to check if it is secured or not and then pop up my password activity in front of it AND recently closed app to reset the flag(i.e if next time it's opened,password activity comes again). Do anybody have some better approach how can i do this??

Usman Riaz
  • 2,920
  • 10
  • 43
  • 66

1 Answers1

0

What you probably need is ActivityManager.getRunningTasks

 ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
 List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks();

You create a service that periodically looks up the running tasks, identifies the new tasks and checks their package using RunningTaskInfo.baseActivity.getPackageName(). Since you know the PID, you can kill the task.

PS. This approach is not 100% proof, because your service can be disabled or uninstalled. Secondly, it wastes memory and battery :)

cyanide
  • 3,885
  • 3
  • 25
  • 33