@Override protected void onNewIntent(Intent intent) { // this method will be triggered by showNotification(message); FragmentManager fm = getSupportFragmentManager(); Bundle bundle = intent.getExtras(); if (bundle != null) { // this activity is launched by notification, show mail fragment now // http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html // http://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-wit // java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState String message = bundle.getString(SMTHApplication.SERVICE_NOTIFICATION_MESSAGE); if (message != null) { // find the actual folder for the new message if (message.contains(SMTHApplication.NOTIFICATION_NEW_MAIL)) { mailListFragment.setCurrentFolder(MailListFragment.INBOX_LABEL); } else if (message.contains(SMTHApplication.NOTIFICATION_NEW_LIKE)) { mailListFragment.setCurrentFolder(MailListFragment.LIKE_LABEL); } else if (message.contains(SMTHApplication.NOTIFICATION_NEW_AT)) { mailListFragment.setCurrentFolder(MailListFragment.AT_LABEL); } else if (message.contains(SMTHApplication.NOTIFICATION_NEW_REPLY)) { mailListFragment.setCurrentFolder(MailListFragment.REPLY_LABEL); } // force mail fragment to reload MailListContent.clear(); fm.beginTransaction() .replace(R.id.content_frame, mailListFragment) .commitAllowingStateLoss(); } } }
@Override public void onMailInteraction(Mail item, int position) { if (item.isCategory) return; // mark item as readed mailListFragment.markMailAsReaded(position); // MailListFragment Intent intent = new Intent(this, MailContentActivity.class); intent.putExtra(SMTHApplication.MAIL_OBJECT, (Parcelable) item); startActivity(intent); }