Android Make a PendingIntent

사용 언어: Kotlin 1.4.30
사용 버전: Android Studio 4.1.2

안드로이드 Make a PendingIntent를 해보겠습니다.


PendingIntent는 앱이 실행되지 않은 상태에서 외부에서 앱의 Intent를  참조하는 것을 말합니다.
여기서 getActivity를 하면, 앱의 Activity를 참조하게 됩니다.
getBroadcast는 앱의 Broadcast를 참조하게 됩니다.


PendingIntent를 만들기 위해서는 Intent가 필요합니다.
먼저 Intent를 만듭니다.









이제, PendingIntent를 만들 차례입니다.

Broadcast를 가져오는 방법입니다.

PendingIntent.getBroadcast를 사용합니다.



Context, Int, Intent, flags가 필요합니다.




다음은 Activity를 가져오는 방법입니다.

인텐트를 만듭니다.








그리고 getActivity를 사용합니다.





Context, Int, Intent, flags가 들어갑니다.

flags에 0이 들어가게 되면 작동은 다음처럼 됩니다. PendingIntent가 존재하면 그 PendingIntent를 사용하고, 없으면 새로 만들게 됩니다.


PendingIntent를 실행하는 방법은 PendingIntent.send를 사용합니다.








마지막으로

NavDeepLinkBuilder를 사용하면 PendingIntent.getActivity와 같은 행동을 합니다.

NavDeepLinkBuilder를 사용하는 이유는 Navigation Component와 호환되기 때문입니다.




setComponentName에는 실행할 Activity를 적습니다.

setGraph에는 res에 있는 Navigation xml 이름을 적습니다.

setDestination은 최종적으로 열릴 Fragment 이름을 적습니다.

createPendingIntent를 사용하여 PendingIntent를 만듭니다.




만약 Safe Args를 사용하여, 열릴 Fragment에 Args 값을 포함해야 하는 경우에는 다음과 같이 사용합니다.







setArguments를 추가하여 Navigation Direction을 적어주고, 해당 action에 필요한 args를 적어줍니다.

그리고 .arguments를 사용하여 Bundle로 만듭니다.



끝.



카테고리: Android

댓글

이 블로그의 인기 게시물

Python OpenCV 빈 화면 만들기

Python urllib.parse.quote()

Python bytes.fromhex()

Android AVD Ram size change

Forensics .pyc 파일 .py로 복구하기

Android Minimum touch target size

KiCad 시작하기 7 (FreeRoute 사용하기 2)

Android Notification with Full Screen

C++ OpenCV 모폴로지 침식, 팽창

KiCad 시작하기 2 (PCB 만들기)