medium.com/androiddevelopers/all-about-pendingintents-748c8eb8619
All About PendingIntents
PendingIntents are an important part of the Android framework, but most of the available developer resources focus on their implementation…
medium.com
Intent는 컴포넌트 끼리 통신을 하기위한 메시지 객체이다.
pendingIntent를 통해서는 다른 어플이 나의 어플을 대신해서 Intent를 발생시키게 해준다.
위의 단어에서 의미하듯이 바로 실행을 하지 않고,
Intent를 생성하여 상호작용을 기다리는 Wrapper을 통해 포장지로 감싼다.
위의 Intent를 실행시키는 동작에 의해 Intent가 작동한다.
Intent를 발생 시켜주기 때문에 어플의 Notification(예)과 Alarm(예)은 앱 자체로서의 활동을 한다고 봐도 됨.
val intent = Intent(applicationContext, MainActivity::class.java).apply {
action = NOTIFICATION_ACTION
data = deepLink
}
val pendingIntent = PendingIntent.getActivity(
applicationContext,
NOTIFICATION_REQUEST_CODE,
intent,
PendingIntent.FLAG_IMMUTABLE
)
val notification = NotificationCompat.Builder(
applicationContext,
NOTIFICATION_CHANNEL
).apply {
// ...
setContentIntent(pendingIntent)
// ...
}.build()
notificationManager.notify(
NOTIFICATION_TAG,
NOTIFICATION_ID,
notification
)
이런식으로 사용하는게 일반적인 Notification 방식인데
원하는 동작을 담은 intent를 작성하여 Notification에 pendingIntent를 통해 제공한다. 즉,
1) notification에 원하는 동작이 담긴 intent를 pendingIntent를 통해 알림(레핑하여 감싼다.)
2) notification 클릭 시에 pendingIntent.send()가 동작하여 Intent를 작동시킴
Android System의 Notification이 내 앱의 Activity를 키게 만듬
위의 예처럼 나의 어플이 외부의 기능들이 내 앱의 권한을 받아 Intent를 전달 할 수 있도록 하는게 핵심이다.
'안드로이드 읽어보기 > 2.Intent' 카테고리의 다른 글
3) Intent와 데이터 공유 (0) | 2022.04.26 |
---|---|
1) Android Intent에 대해서 (0) | 2022.04.23 |