[Android] Activity Stack, Task 확인하기
Android 개발을 하면서 StartActivity를 여러 번 하다보면 Activity들이 생각한 대로 쌓였는지 확인해야 할 때가 생길 수 있습니다. 저는 launchMode랑 Intent Flag들을 공부하면서 사용해 보던 중 Activity Stack..
ohdbjj.tistory.com
YouTube, Facebook 등 다양한 앱들의 Activity Stack을 확인하던 중 Chrome 앱이 Back키를 눌러 앱을 종료했을 때도 Background에 살아있더군요. 신기하여 관련 코드를 찾아보았습니다.
@Override
public void onBackPressed() {
/*
둘 다 동일하게 작동합니다.
MoveTaskToBack의 인자가 true일 땐 RootActivity에서 호출되었을 때만 Background로
false일 땐 그냥 Background로 보내버립니다.
*/
//moveTaskToBack(true);
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
}
startActivity로 홈 화면으로 가지는 게 재밌는거 같습니다.
https://stackoverflow.com/questions/10461095/moving-application-in-background-on-back-button-event
Moving application in background on back button event
Is it possible to move the app in background when we click on device back button in android? background means application moves to screen(application) from where it launches ?
stackoverflow.com
'Android' 카테고리의 다른 글
[Android] findViewById가 귀찮을 때 (0) | 2020.02.21 |
---|---|
[Android] View의 getLeft, getTop, getRight, getBottom 메서드 (0) | 2020.02.14 |
[Android] onMeasure 함수의 인자들 (0) | 2020.02.05 |
[Android] EditText가 아닌 다른 곳 클릭시 키보드 내리기 (0) | 2020.02.02 |
[Android] Activity Stack, Task 확인하기 (0) | 2020.01.31 |