Android App
앱 종료 시점알기, 앱종료인지 아니면 Activity끼리 전환인지 구분
동동(이재동)
2014. 8. 27. 11:48
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;
}
onPause()를 오버라이드 해서
boolean temp = isApplicationSentToBackground(this);
사용하면 된다.
true일때는 사용자가 홈버튼을 눌렀을때 혹은 앱을 나갔을때
false일때는 나가지 않고 activity로 이동