Before asking this question, I did a lot of search. But none of the answers here did work for me:
onNewIntent is not called,
onNewIntent not called on restart,
onNewIntent() not getting called in some devices,
my onNewIntent is not calling
I am working on NotificationManager
where my requirement is to open an Activity
on tap of notification with values received through that notification.
I have tried the following piece of code while setting intent:
Intent notificationIntent = new Intent(context, MyActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
I also set launchMode
as singleTop
in Manifest.xml
:
<activity android:name=".MyActivity" android:hardwareAccelerated="true" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.google.com"
android:scheme="http" />
</intent-filter>
</activity>
The issue seems to be device specific. I tried the same piece of code on Nexus 7
and onNewIntent
is being called there. But somehow it is not working on Galaxy S4.
Questions:
- Have you guys faced similar problem in the past?
- How do I fix it?
- My biggest curiosity lies on "How can an API be device specific?"
- Can I rely on
onNewIntent
API or should I look for an alternative? As observed, it seems like this issue doesn't repro on all devices. And I cannot test on all devices for its reliability.