티스토리 뷰

반응형

안드로이드 앱 개발 중에 홈버튼에 대한 이슈가 발생함. 

꺼진화면, 잠금화면에 대해 lifecycle이 2번 도는데 (API 26이하까지), 그렇다면 꺼진화면 & 잠금화면일 경우, 총 onStop이 3번 돌아야 된다고 생각한다. ( 이미 꺼진 화면 stop 한번 , 잠겼으니 stop 한번, 최종적으로 activity 꺼질 경우(activity에 대해서 꺼지는 행동만 할 수 있다는 가정하에..) stop 한번 ) 

..... 그러나, 실제 run으로 확인하면 stop이 2번만 될 때도 있고, 3 번이 될 수 도 있다(심한욕...)....,,,,

 

그래서 아예 activity가 꺼지는 상황이 발생했을 경우에만 onDestroy 되게 끔, 수정해야 한다. 

1. swipe 를 사용했을 때,

2. 홈버튼 눌렀을 때... 

 

여기서 홈버튼 눌렀을 때를 확인할 때, onUserLeaveHint 메소드를 사용한다. 

 

Activity 코드에서 발췌한 내용

- 사용자의 행동으로 인해, Background로 Activity가 전환될 경우에 호출되는 메소드

/**
* Called as part of the activity lifecycle when an activity is about to go
* into the background as the result of user choice. For example, when the
* user presses the Home key, {@link #onUserLeaveHint} will be called, but
* when an incoming phone call causes the in-call Activity to be automatically
* brought to the foreground, {@link #onUserLeaveHint} will not be called on
* the activity being interrupted. In cases when it is invoked, this method
* is called right before the activity's {@link #onPause} callback.
*
* <p>This callback and {@link #onUserInteraction} are intended to help
* activities manage status bar notifications intelligently; specifically,
* for helping activities determine the proper time to cancel a notification.
*
* @see #onUserInteraction()
* @see android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION
*/

 

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함