I have a FragmentActivity with a list of items, and when the app is in background, there can be a push to that item list.
when this happens, I want to create a statusbar notification and alert the user on the update.
when the user clicks the notification, the activity should reorder to front and show on the screen while showing the new item at the bottom of a list.
so I write a notification manager that shows that on the users device:
private static void createNotification(String title, String text,
String largeIcon, String itemdId, Context mCOntext) {
Bitmap ic = BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.ic_launcher);
Intent intent = new Intent(mContext, MyFragmentActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra(MyFragmentActivity.SELECTED_ITEM_LIST_ID, DatabaseHelper
.getItemListById(listId).getId());
PendingIntent pIntent = PendingIntent.getActivity(mContext, 0, intent,
0);
Notification noti = new NotificationCompat.Builder(mContext)
.setContentTitle(title).setContentText(text)
.setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent)
.setAutoCancel(true).setLargeIcon(ic).build();
noti.defaults |= Notification.DEFAULT_LIGHTS;
noti.defaults |= Notification.DEFAULT_VIBRATE;
noti.sound = Uri.parse("android.resource://"
+ mContext.getPackageName() + "/" + R.raw.user_gets_message);
NotificationManager nm = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
The only issue is that it seems to ignore my flag, when I navigate to the fragment activity, and then go to my home screen (background the app), and get a push, when I click on the notification, the app creates a new Activity (or fragment) and shows the new one instead of the original with the new data. (this means that clicking the back button opens the same activity (or fragment) from the history stack.
I overridden the onNewIntent
and all the life cycle methods of the activity and I saw that on back clicked, the methods that are called are the MyFragmentActivity.onStart
and the MyFragmentActivity.onResume
.
any thoughts on what it is that I'm doing wrong?