When I get new notification, I redirect the user to a AFragment
but get me bellow error.Bellow I get notification:
class NotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
private final Context context;
NotificationOpenedHandler(Context context) {
this.context = context;
}
// This fires when a notification is opened by tapping on it.
@Override
public void notificationOpened(OSNotificationOpenResult result) {
OSNotificationAction.ActionType actionType = result.action.type;
JSONObject data = result.notification.payload.additionalData;
String link;
if (data != null) {
link = data.optString("link", null);
if (link != null && !TextUtils.isEmpty(link)) {
try {
String idLang = new SessionManager(context).getIdLanguage();
if (idLang != null && !TextUtils.isEmpty(idLang)) {
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("LINK", link);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
} else {
Intent intent = new Intent(context, StartActivity.class);
context.startActivity(intent);
}
} catch (Exception ex) {
Throwable t = new Throwable(ex).fillInStackTrace();
FirebaseCrash.report(t);
}
}
}
}
}
Then from MainActivity
redirect user to AFragment
then redirect to NotificationFragment
like bellow:
if (getActivity() != null && isResumed() && !isRemoving()) {
redirectNotification = false;
NotificationFragment notificationFragment = new NotificationFragment();
Bundle arguments = new Bundle();
arguments.putString("URL_NOTIFICATION", urlNotification);
notificationFragment.setArguments(arguments);
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.frame_work_table_fragment,
notificationFragment,
getString(R.string.notification_fragment))
.addToBackStack(getString(R.string.notification_fragment))
.commit();
}
But get me bellow error:
Exception java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState