1

Open the app through clicked notification and then clear intent action

If the app in the background, push the local notification and click the notification and open the MainActivity

public static void publishLocalNotification(...){
  NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, "Start")
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setSmallIcon(R.drawable.local_notification)
                .setContentTitle(title)
                .setPriority(Notification.PRIORITY_HIGH) 
                .setContentText(message);

  resultIntent = new Intent(mContext, MainActivity.class);

  resultIntent.setAction(action);
  ...
  PendingIntent pendingIntent = PendingIntent.getActivity(mContext,-1, resultIntent, PendingIntent.FLAG_ONE_SHOT);

  builder.setContentIntent(pendingIntent);

}


In the Main activity 

@Override
protected void onResume() {
  super.onResume();
  String action = getIntent().getAction();

  if(action != null){

     ... Show dialog



  }

}





If app cannot clear intent action. Each time, when app from background to foreground, the onResume() would be called and the dialog would be shown each time

David Wasser
  • 93,459
  • 16
  • 209
  • 274
Chih Yang
  • 11
  • 3

1 Answers1

-1

See my extensive discussion of this problem (Persistent data in an Intent in a `Notification) here:

Remove data from notification intent

If you just want to ensure that your dialog is shown once, you can do the following in onResume():

Intent intent = getIntent(); // Get the Intent that the app was started with

if (intent.getAction() ) {
    // Show dialog ...
}
intent.setAction(null); // Clear the ACTION in the intent and
setIntent(intent);      //  replace it to prevent the dialog from being shown again

But it is possible that I don't understand 100% your requirements.

David Wasser
  • 93,459
  • 16
  • 209
  • 274