getIntent() Extras always NULL

This is the scenario:
The method getIntent() returns the FIRST intent than launch activity.

So, when the activity is CLOSED (terminated) and the user clicks on the notification, it will run a new instance of the activity and getIntent() works as expected (Extras is not null).

But if the activity is “sleeping” (it is in the background) and the user clicks on the notification, getIntent() always returns the very FIRST intent that started the activity and NOT the notification intent.

So to catch the notification intent while the application is running, simply use this

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

and then override onNewIntent(Intent newintent).

So when an application first runs, getIntent() can be used and when application is resumed from sleeping, onNewIntent works.

Leave a Comment