I saw several approaches and I tried everything but couldnt make it work.I dont know why it is so complicated, in the docs it looks so easy! I want to trigger the OnNewInten
As first, you should add android:launchMode="singleTop"
to your activity definition in manifest file like below
Then like Hasan Masud said that, you should add Intent.ACTION_MAIN
and Intent.CATEGORY_LAUNCHER
to your action like below
Intent intent = new Intent(this, MainActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
That's all. With this way, if the app is open and when you click the notification, onNewIntent(..) method will trigger but whatever happens, if the app is close, when you click the notification, notification intent will go to the onCreate(..) method of current Activity.