1

내 안드로이드 앱에서 FCM을 사용하여 알림을 표시하고 있습니다. 한 가지 문제를 제외하고 모든 것이 예상대로 작동합니다.알림을 클릭 할 때 모든 스택 지우기

사용자가 알림을 클릭하면 내 앱의 모든 백그라운드 및 전경 활동을 닫고 알림에 지정된 인 텐트를 열어야합니다.

어떻게하면됩니까? 난 당신이

intentToLaunch.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     intentToLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

답변

2

같은 대기 의도를 사용하고

,

NotificationManager notificationManager = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification notification = new Notification(icon, message, when); 

    Intent notificationIntent = new Intent(context, HomeActivity.class); 

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

    PendingIntent intent = PendingIntent.getActivity(context, 0, 
      notificationIntent, 0); 

    notification.setLatestEventInfo(context, title, message, intent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notificationManager.notify(0, notification);   
1

이 시도하는 모든 스택을 취소 2 개 플래그를 사용할 수있는이

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     final PendingIntent resultPendingIntent = 
       PendingIntent.getActivity(
         mContext, 
         0, 
         intent, 
         PendingIntent.FLAG_CANCEL_CURRENT 
       ); 
관련 문제