Skip to content

Commit

Permalink
fix initial notification from killed (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielEliraz authored Feb 28, 2022
1 parent b667267 commit e6b178c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,13 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(mApplication.getApplicationContext());
notificationsDrawer.onNewActivity(activity);

Intent intent = activity.getIntent();
if (NotificationIntentAdapter.canHandleIntent(intent)) {
Bundle notificationData = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R ?
NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent) : intent.getExtras();
final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData);
if (pushNotification != null) {
pushNotification.onOpened();
}
}
callOnOpenedIfNeed(activity);
}

@Override
public void onActivityStarted(Activity activity) {
Bundle bundle = activity.getIntent().getExtras();
if (bundle != null) {
PushNotificationProps props = new PushNotificationProps(bundle);
if (props.isFirebaseBackgroundPayload()) {
InitialNotificationHolder.getInstance().set(props);
}
if (InitialNotificationHolder.getInstance().get() == null) {
callOnOpenedIfNeed(activity);
}
}

Expand All @@ -102,4 +90,16 @@ public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
@Override
public void onActivityDestroyed(Activity activity) {
}

private void callOnOpenedIfNeed(Activity activity) {
Intent intent = activity.getIntent();
if (NotificationIntentAdapter.canHandleIntent(intent)) {
Bundle notificationData = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R ?
NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent) : intent.getExtras();
final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData);
if (pushNotification != null) {
pushNotification.onOpened();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.wix.reactnativenotifications.core.InitialNotificationHolder;
import com.wix.reactnativenotifications.core.JsIOHelper;
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
import com.wix.reactnativenotifications.core.ProxyService;

import static com.wix.reactnativenotifications.Defs.NOTIFICATION_OPENED_EVENT_NAME;
import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME;
Expand Down

0 comments on commit e6b178c

Please sign in to comment.