Android에서 실제로 문제가되는 경우입니다. 나를 위해 일한 다음을 시도하십시오 :
귀하의 활동을위한 기본 수업을 준비하십시오. 이 글은 :
public static void wentInBackground(final Activity which) {
inBackground = true;
lastPaused = which.getClass().getSimpleName();
final PowerManager powerManager = (PowerManager) which.getSystemService(POWER_SERVICE);
final boolean isScreenOn = powerManager.isScreenOn();
if (isApplicationSentToBackground(which) || !isScreenOn) {
// Do your security lockdown here.
}
}
public static boolean isApplicationSentToBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
public static void wentInForeground(final Activity which) {
inBackground = false;
final String activityName = which.getClass().getSimpleName();
if (lastPaused.equals(activityName) || !isLoggedIn()) {
if (isLoggedIn()) {
// Do your security lockdown here again, if necessary.
}
// Show your security screen or whatever you need to.
}
}
public static boolean isLoggedIn() {
return loggedIn;
}
당신의 질문이 무엇인지 정말 분명하지 않다 :
그리고 정적 유틸리티 클래스에서이 있습니다. 또한 어떤 isApplicationBroughtToBackground() 메소드도 모른다. 그거 어디서 났어? – nicopico