안드로이드 펜딩 인텐트(Pending Intent)

Intro

Pending Intent에 대해서 알아보기

Pending Intent

PendingIntentIntent를 가지고 있는 클래스로 가지고있는 인텐트를 보류하고 특정 시점에 작업을 요청 하도록 하는 특징을 가지고 있다.

Notification을 통해 인텐트를 실행 하도록 하거나 특정 시점에 AlarmManger를 이용하여 인텐트를 실행 할 때 사용한다.

Activity를 시작하는 인텐트

getActivity(Context, int, Intent, int)

BroadcastRecevier를 시작하는 인텐트

getBroadcast(Context, int, Intent, int)

Service를 시작하는 인텐트

getService(Context, int, Intent, int)

예제

Intent intent = new Intent(this, MainActivity.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(this,
                0,
                intent,
                PendingIntent.FLAG_CANCEL_CURRENT);

위의 PendingIntent를 통해 Notification을 클릭하면 MainActivity가 실행된다.

각 FLAG의 의미

FLAG_CANCEL_CURRENT : 이전에 생성한 PendingIntent는 취소하고 새로 만든다.

FLAG_IMMUTABLE : 생성된 PendingIntent를 수정 불가능 하게 한다.

FLAG_NO_CREATE : 생성된 PendingIntent 를 반환한다.(재사용 가능)

FLAG_ONE_SHOT : 해당 Flag로 생성한 PendingIntent는 일회성이다.

FLAG_UPDATE_CURRENT : 이미 생성된 PendingIntent가 존재하면 해당 IntentExtra Data를 대체

실행 결과

1

참고자료

https://developer.android.com/reference/android/app/PendingIntent

댓글남기기