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