I am trying to launch an intent from a notification, but for a reason I don’t know the extra is not always sent with the intent.
This is where I create the intent :
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
mContext.getString(R.string.text), 0);
Intent intents = new Intent(mContext, DataAppTabs.class);
intents.putExtra(DataAppTabs.REQUEST, DataAppTabs.REQUEST_DMTAB);
intents.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent launchIntent = PendingIntent.getActivity(mContext.getApplicationContext(), DataAppTabs.REQUEST_DMTAB, intents, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(mContext, "Info", mContext.getString(R.string.enginedmnotification_rebootneeded), launchIntent);
notification.flags = Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notification.defaults = Notification.DEFAULT_ALL;
notificationManager.notify(DataAppTabs.REQUEST_DMTAB, notification);
In the DataAppTabs class I overrided onCreate() and onNewIntent(). When the notification appears, if I click on it it opens the correct Activity (DataAppTabs, which is a TabActivity), it triggers onCreate or onNewIntent if the activity was already started, but the extra “REQUEST” is not always set (getExtras() is sometimes null).
I have found the same question here with answers telling me I had to use the “FLAG_ACTIVITY_SINGLE_TOP” flag, but it still doesn’t work all the time and I am not able to reproduce the problem every time.
Is it something I did wrong ?
Thanks
1 Answer