Recent Posts
Recent Comments
«   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
Tags more
Archives
Today
Total
관리 메뉴

RamaFam

주로 사용되는 Activity FLAG 본문

카테고리 없음

주로 사용되는 Activity FLAG

RamaFam 2018. 7. 25. 17:05
휴휴님의 블로그 참조 : http://huewu.blog.me/110087045138
전체 FLAG의 정보는 android 사이트 참조 : http://developer.android.com/reference/android/content/Intent.html

주로 사용되는 4가지 FLAG

FLAG_ACTIVITY_SINGLE_TOP
Activity가 스택의 맨 위에 존재 하는 경우에 기존 Activity를 재활용 한다.

(Activity호출순서) 0->1->2->3   이렇게 스택이 쌓인 경우(스택의 맨 위는 3)   

intent = new Intent(this, Activity3.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

0->1->2->3 그래도 유지 된다. 대신 Activity3는 onPause()->onNewIntent() -> onResume() 호출된다.
3번 액티비티가 존재하지 않거나 스택의 맨 위가 아닌 경우 그냥 스택에 쌓이게 되며 onNewIntent() 도 호출된다.


FLAG_ACTIVITY_NO_HISTORY
해당 플래그를 주고 액티비티를 호출하면 호출된 액티비티는 스택에 남지 않는다.
0->1->2->3  호출할때 Activity1 에서 Activity 2를 호출할때 
intent = new Intent(this, ActivityTest3.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
하면 스택에는 0->1->3 만 남게 된다.  하지만 Activity 2의 Destory()의 시점은 Activity 3이 종료 된 이후에 호출된다라는것을 주의한다.


FLAG_ACTIVITY_REORDER_TO_FRONT
스택의 순서를 변경해 준다.
0->1->2->3 일때 Activity 3에서 Activity 1을 호출 할때 이 플래그를 설정하면 
0->2->3->1 로 변경된다. (안드로이드 문서에서 FLAG_ACTIVITY_CLEAR_TOP플래그를 무시한다고 되어 있다.)


FLAG_ACTIVITY_CLEAR_TOP
스택에 기존에 사용하던 Activity가 있다면 그 위의 스택을 전부 제거해 주고 호출한다.
0->1->2->3 일때 Activity 3에서 Activity 1을 호출할때 이 플래그를 설정하면
0->1 만 남게 된다. (2, 3은 제거)  이때 Activity 1은 onDestory() -> onCreate()가 호출된다. 삭제하고 다시 만들게 된다.

그래서~~ FLAG_ACTIVITY_SINGLE_TOP와 같이 써준다. 그러면 onNewIntent()-> onResume() 가 호출된다.
만약 스택에 없다면~~ 당연히 아무것도 지우지 못하고 맨 위에 올라가게 된다.

intent = new Intent(this, ActivityTest1.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);



출처: http://comxp.tistory.com/109 [까칠하게...]

Comments