[Android] Notification 클릭 시 앱 중복 실행 문제

jeongsik kim·2020년 11월 11일
0

앱 개발 중 FCM을 이용해서 PUSH 서비스를 구현했을때,
Notification 클릭 시 앱으로 진입을 하는데 앱이 백그라운드 상태일 경우에는 중복 실행이 되는 현상이 발생한다.

  • 앱이 백그라운드 상태에서 푸시를 받았을 경우 Notification 클릭 시 앱 중복 실행 방지
  • 백그라운드에 실행 중인 앱을 포어그라운드 상태로 변경하고 사용 중이던 Activity 유지
  • 앱이 stack에서 제거되어 종료되었을 경우 앱 실행

해결 방법은 아래와 같다.

val intent = Intent(baseContext, MainActivity::class.java)
intent.action = Intent.ACTION_MAIN
intent.addCategory(Intent.CATEGORY_LAUNCHER)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val pIntent = PendingIntent.getActivity(baseContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

출처 : https://like-tomato.tistory.com/156

profile
Android=Kotlin, iOS=Swift, CrossPlatform=Flutter

0개의 댓글