lockAppName 是需要判断Activity的全称(包括包名).

private boolean getTopApp(Context mContext) {
String lockAppName = "com.celltick.lockscreen.LockerActivity";
String topActivityName = "";
ActivityManager am = (ActivityManager) mContext
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTasks = am
.getRunningTasks(1);
if (runningTasks != null && !runningTasks.isEmpty()) {
ActivityManager.RunningTaskInfo taskInfo = runningTasks.get(0);
topActivityName = taskInfo.topActivity.getClassName();
}
if (lockAppName.equals(topActivityName)) {
return true;
}
return false;
}
05-07 15:55