I have a FragmentActivity with a list of elements, and when the application is in the background, there may be a click on this list of elements.
when this happens, I want to create a notification in the status bar and notify the user about the update.
When the user clicks on the notification, the action should be reordered forward and show on the screen when showing a new item at the bottom of the list.
so I write a notification manager that shows what is on the user 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 problem is that it seems to ignore my flag when I go to fragment activity and then go to the main screen (background application) and get push, when I click on the notification, the application creates a new activity (or fragment) and shows a new, not original, with new data. (this means that pressing the "Back" button opens the same activity (or fragment) from the history stack.
I redefined onNewIntent and all the lifecycle methods of this activity, and I saw that on the callback, the methods that are called are MyFragmentActivity.onStart and MyFragmentActivity.onResume .
Any thoughts on what I'm doing wrong?