SlideShare a Scribd company logo
1 of 6
PendingIntent는 뭘까?
Intent를 만들어서 다시 PendingIntent에 담아서 쓴다?!
도대체 이 PendingIntent는 뭘까?
PendingIntent는 뭘까요?
내 권한을 부여해서, 전달을 한 intent라 생각할 수 있다.
간단하면서도 자주 사용되는 예로 생각하면, Notification이 있을 수 있습니다.
Notification는 Activity가 아닙니다.
그렇기에 intent를 통해서 startActivity 수행을 하지 못 하지요.
그런데, 우리는 Notification이 클릭 될 때,
마치 Activity에서 startActivity를 호출하는 것과 같이 수행을 하고 싶습니다.
이러한 경우에 현재 startActivity를 호출할 수 있는 나의 권한까지 같이 부여해서 Intent를 생성하
게 되면, 그것이 바로 PendingIntent가 된다고 생각할 수 있습니다.
지금은 startActivity를 시키는 권한에 대한 위임에 대해서 이야기 했지만, 이 외에 특정 동작을 수
행을 특정 Activity만 할 수 있는데, 이를 다른 Activity에서도 할 수 있게 하고자 허용하고자 할 때
도 이 PendingIntent를 사용할 수 있는 것이다.
마치 내 방 열쇠를 주고 필요할 때, 특정 시점에 내 대신 방 청소 좀 해주라고
이야기하고자 하는 것이 PendingIntent를 주는 것이라고 이해할 수 있으리
라 생각합니다.
PendingIntent 좀 더 알기
By giving a PendingIntent to another application, you are granting it the
right to perform the operation you have specified as if the other
application was yourself (with the same permissions and identity)
앞 서 설명한 내용이 바로 위 문장으로 정리가 될 수 있습니다.
그리고 추가적으로 이 PendingIntent가 권한이 위임되는 특성이 있기 때문
에 사용서에 대해서 별도 Flag 값을 지정이 가능합니다.
FLAG_CANCEL_CURRENT
PendingIntent already exists, the current one is canceled before generating a new one.
FLAG_NO_CREATE
PendingIntent does not already exist, then simply return null instead of creating it.
FLAG_ONE_SHOT
this PendingIntent can only be used once.
FLAG_UPDATE_CURRENT
PendingIntent already exists, then keep it but its replace its extra data with what is in this new Intent.
PendingIntent 활용 요약
활용 예로 앞서서는 특정 activity를 start 시키는 것을 생각해 봤는데, 추가로
예를 들면, PendingIntent.getBroadcast를 통해서 특정 시점에 BroadCast를
대신 수행하게 할 수도 있습니다.
즉 PendingIntent는 2가지 측면에서 활용도를 생각합니다.
• 현재가 아닌 미래 특정 Event 시점에 동작하도록 예약하기 위해서
• 특정 동작을 해당 시점에 내가(현재 Activity)가 떠 있지 않더라도 떠 있는
것과 같이 동작할 수 있도록 설정하기 위해서.
이러한 동작을 수행하는 조건을 앞서 살펴본 Flag들을 설정해서, 1회성으로
쓰게 할지 아니면 1번만 사용할지, 아니면 매번 최신 정보로 업데이트할 지를
결정하게 됩니다.
참고자료
• API:
http://developer.android.com/reference/android/app/PendingIntent.html
• PendingIntent 플래그에 대한 활용 예.
http://androidhub.wordpress.com/tag/flag_cancel_current/
• 알람에서 활용하는 예. http://comxp.tistory.com/53
• PendingIntent 플래그 사용에 대한 고민
http://www.androidside.com/plugin/mobile/board.php?bo_table=B49&wr_id
=59094

More Related Content

More from 운용 최

21 application and_network_status
21 application and_network_status21 application and_network_status
21 application and_network_status운용 최
 
20 handler and_async_task
20 handler and_async_task20 handler and_async_task
20 handler and_async_task운용 최
 
18 안드로이드 리스트뷰_속도향상
18 안드로이드 리스트뷰_속도향상18 안드로이드 리스트뷰_속도향상
18 안드로이드 리스트뷰_속도향상운용 최
 
19 나만의 view 만들기
19 나만의 view 만들기19 나만의 view 만들기
19 나만의 view 만들기운용 최
 
17 adapter view & db
17 adapter view & db17 adapter view & db
17 adapter view & db운용 최
 
16 데이터 저장과 사용
16 데이터 저장과 사용16 데이터 저장과 사용
16 데이터 저장과 사용운용 최
 
15 content provider
15 content provider15 content provider
15 content provider운용 최
 
14 broad castreceiver
14 broad castreceiver14 broad castreceiver
14 broad castreceiver운용 최
 
11 tablet 대응 가이드
11 tablet 대응 가이드11 tablet 대응 가이드
11 tablet 대응 가이드운용 최
 
09 android keyboard & layout
09 android keyboard & layout09 android keyboard & layout
09 android keyboard & layout운용 최
 
07 다양한 device_대응_방법
07 다양한 device_대응_방법07 다양한 device_대응_방법
07 다양한 device_대응_방법운용 최
 
04 activity간에 호출하기 & intent
04 activity간에 호출하기 & intent04 activity간에 호출하기 & intent
04 activity간에 호출하기 & intent운용 최
 
03 activity.finish
03 activity.finish03 activity.finish
03 activity.finish운용 최
 
02 activity.lifecycle
02 activity.lifecycle02 activity.lifecycle
02 activity.lifecycle운용 최
 
안드로이드 로그 파일로 남기기
안드로이드 로그 파일로 남기기안드로이드 로그 파일로 남기기
안드로이드 로그 파일로 남기기운용 최
 
다양한 Device 대응_방법
다양한 Device 대응_방법다양한 Device 대응_방법
다양한 Device 대응_방법운용 최
 
안드로이드 화면 전환에 따른 동작 예제
안드로이드 화면 전환에 따른 동작 예제안드로이드 화면 전환에 따른 동작 예제
안드로이드 화면 전환에 따른 동작 예제운용 최
 

More from 운용 최 (20)

Uml intro 1
Uml intro 1Uml intro 1
Uml intro 1
 
Uml intro 0
Uml intro 0Uml intro 0
Uml intro 0
 
21 application and_network_status
21 application and_network_status21 application and_network_status
21 application and_network_status
 
20 handler and_async_task
20 handler and_async_task20 handler and_async_task
20 handler and_async_task
 
18 안드로이드 리스트뷰_속도향상
18 안드로이드 리스트뷰_속도향상18 안드로이드 리스트뷰_속도향상
18 안드로이드 리스트뷰_속도향상
 
19 나만의 view 만들기
19 나만의 view 만들기19 나만의 view 만들기
19 나만의 view 만들기
 
17 adapter view & db
17 adapter view & db17 adapter view & db
17 adapter view & db
 
16 데이터 저장과 사용
16 데이터 저장과 사용16 데이터 저장과 사용
16 데이터 저장과 사용
 
15 content provider
15 content provider15 content provider
15 content provider
 
14 broad castreceiver
14 broad castreceiver14 broad castreceiver
14 broad castreceiver
 
11 tablet 대응 가이드
11 tablet 대응 가이드11 tablet 대응 가이드
11 tablet 대응 가이드
 
09 android keyboard & layout
09 android keyboard & layout09 android keyboard & layout
09 android keyboard & layout
 
08 font size
08 font size08 font size
08 font size
 
07 다양한 device_대응_방법
07 다양한 device_대응_방법07 다양한 device_대응_방법
07 다양한 device_대응_방법
 
04 activity간에 호출하기 & intent
04 activity간에 호출하기 & intent04 activity간에 호출하기 & intent
04 activity간에 호출하기 & intent
 
03 activity.finish
03 activity.finish03 activity.finish
03 activity.finish
 
02 activity.lifecycle
02 activity.lifecycle02 activity.lifecycle
02 activity.lifecycle
 
안드로이드 로그 파일로 남기기
안드로이드 로그 파일로 남기기안드로이드 로그 파일로 남기기
안드로이드 로그 파일로 남기기
 
다양한 Device 대응_방법
다양한 Device 대응_방법다양한 Device 대응_방법
다양한 Device 대응_방법
 
안드로이드 화면 전환에 따른 동작 예제
안드로이드 화면 전환에 따른 동작 예제안드로이드 화면 전환에 따른 동작 예제
안드로이드 화면 전환에 따른 동작 예제
 

05 pending intent

  • 2. Intent를 만들어서 다시 PendingIntent에 담아서 쓴다?! 도대체 이 PendingIntent는 뭘까?
  • 3. PendingIntent는 뭘까요? 내 권한을 부여해서, 전달을 한 intent라 생각할 수 있다. 간단하면서도 자주 사용되는 예로 생각하면, Notification이 있을 수 있습니다. Notification는 Activity가 아닙니다. 그렇기에 intent를 통해서 startActivity 수행을 하지 못 하지요. 그런데, 우리는 Notification이 클릭 될 때, 마치 Activity에서 startActivity를 호출하는 것과 같이 수행을 하고 싶습니다. 이러한 경우에 현재 startActivity를 호출할 수 있는 나의 권한까지 같이 부여해서 Intent를 생성하 게 되면, 그것이 바로 PendingIntent가 된다고 생각할 수 있습니다. 지금은 startActivity를 시키는 권한에 대한 위임에 대해서 이야기 했지만, 이 외에 특정 동작을 수 행을 특정 Activity만 할 수 있는데, 이를 다른 Activity에서도 할 수 있게 하고자 허용하고자 할 때 도 이 PendingIntent를 사용할 수 있는 것이다. 마치 내 방 열쇠를 주고 필요할 때, 특정 시점에 내 대신 방 청소 좀 해주라고 이야기하고자 하는 것이 PendingIntent를 주는 것이라고 이해할 수 있으리 라 생각합니다.
  • 4. PendingIntent 좀 더 알기 By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity) 앞 서 설명한 내용이 바로 위 문장으로 정리가 될 수 있습니다. 그리고 추가적으로 이 PendingIntent가 권한이 위임되는 특성이 있기 때문 에 사용서에 대해서 별도 Flag 값을 지정이 가능합니다. FLAG_CANCEL_CURRENT PendingIntent already exists, the current one is canceled before generating a new one. FLAG_NO_CREATE PendingIntent does not already exist, then simply return null instead of creating it. FLAG_ONE_SHOT this PendingIntent can only be used once. FLAG_UPDATE_CURRENT PendingIntent already exists, then keep it but its replace its extra data with what is in this new Intent.
  • 5. PendingIntent 활용 요약 활용 예로 앞서서는 특정 activity를 start 시키는 것을 생각해 봤는데, 추가로 예를 들면, PendingIntent.getBroadcast를 통해서 특정 시점에 BroadCast를 대신 수행하게 할 수도 있습니다. 즉 PendingIntent는 2가지 측면에서 활용도를 생각합니다. • 현재가 아닌 미래 특정 Event 시점에 동작하도록 예약하기 위해서 • 특정 동작을 해당 시점에 내가(현재 Activity)가 떠 있지 않더라도 떠 있는 것과 같이 동작할 수 있도록 설정하기 위해서. 이러한 동작을 수행하는 조건을 앞서 살펴본 Flag들을 설정해서, 1회성으로 쓰게 할지 아니면 1번만 사용할지, 아니면 매번 최신 정보로 업데이트할 지를 결정하게 됩니다.
  • 6. 참고자료 • API: http://developer.android.com/reference/android/app/PendingIntent.html • PendingIntent 플래그에 대한 활용 예. http://androidhub.wordpress.com/tag/flag_cancel_current/ • 알람에서 활용하는 예. http://comxp.tistory.com/53 • PendingIntent 플래그 사용에 대한 고민 http://www.androidside.com/plugin/mobile/board.php?bo_table=B49&wr_id =59094