안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요.
개발자 사이트를 보면
public static final int FLAG_ACTIVITY_SINGLE_TOP
Since: API Level 1
If set, the activity will not be launched if it is already running at the top of the history stack.
Constant Value: 536870912 (0x20000000)
public static final int FLAG_RECEIVER_REPLACE_PENDING
Since: API Level 8
If set, when sending a broadcast the new broadcast will replace any existing pending broadcast that matches it. Matching is defined by Intent.filterEquals returning true for the intents of the two broadcasts. When a match is found, the new broadcast (and receivers associated with it) will replace the existing one in the pending broadcast list, remaining at the same position in the list.
This flag is most typically used with sticky broadcasts, which only care about delivering the most recent values of the broadcast to their receivers.
Constant Value: 536870912 (0x20000000)
FLAG_ACTIVITY_SINGLE_TOP
- 태스크의 최상위에 이미 실행되고 있으면 새로운 activity를 생성하지 않음
FLAG_RECEIVER_REPLACE_PENDING
- 보류 중인 broadcast가 있으면 새로운 broadcast로 대체함. 일반적으로 sticky broadcast에서 사용됨.
이 정도로 해석하면 될 것 같은데요.
궁금한 것은 두 변수의 상수값이 0x20000000으로 같다는 것입니다.
그래서 예상한 것이
1. 일반적인 broadcast에는 FLAG_ACTIVITY_SINGLE_TOP 이 적용되고
sticky broadcast에는 FLAG_RECEIVER_REPLACE_PENDING 이 적용됨.
2. 사용하는 API 버전에 따라 구분됨.
일단 위의 내용에는 1번이 맞을 거라 생각하는데,
이것 말고
FLAG_ACTIVITY_NO_HISTORY 와 FLAG_RECEIVER_REGISTERED_ONLY 도 상수값이 0x40000000로 같습니다.
이건 API 버전도 같습니다;; 혹시 이 것도 아신다면 조언 부탁드립니다.
감사합니다.
오늘도 수고하세요 : )
2011.11.30 11:35:38
다음과 같이 볼수 있을것입니다.
FLAG_ACTIVITY_...은 startActivity에서 사용할 intent에 관한 FLAG입니다.
FLAG_RECEIVER_...은 sendBroadcast에서 사용할 intent에 관한 FLAG입니다.
상수를 숫자를 바로 쓰지 않고 저렇게 대체할 이름을 사용하는 것은 혼동을 줄이기 위함입니다.
잘못사용하여 내가 원하지 않는 방향으로 진행될수 있으나 말그대로 잘못사용한쪽이 잘못이구요.
저렇게 같은 숫자를 이용하지만 상수 이름을 다르게 붙여서 용도가 다름을 명시하는 방식은
여기저기서 알게 모르게 상당히 많이 사용되고 있습니다.




제목 글좀 좀 줄여주세요, 게시판 목록이 많이 망가지네요 부탁드려요~