React-native-navigation: Android app restarts when opening push notification

Created on 9 Feb 2018  路  7Comments  路  Source: wix/react-native-navigation

I'm working on a project that uses react-native-notification on Android. When I open a push notification it opens the app but I notice that the SplashActivity displays for a couple of seconds. Effectively, it restarts the app instead of resuming the app.

Here's how to reproduce:

  1. Open app from launcher or appDrawer
  2. Go home
  3. Send notification and open
  4. It creates a new SplashActivity and destroys the old NavigationActivity
  5. Causing an unnecessary app restart

One thing to note, if the app is started from a push notification the app works fine for any subsequent notifications (resumes every time instead of restart)
It's only when you start app from launcher or appDrawer.

I found a solution that short-circuits the app restart:

public class MainActivity extends SplashActivity {
@Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!isTaskRoot()) {
      finish();
      return;
    }
  }
}

here's the link for reference: https://stackoverflow.com/questions/7944338/resume-last-activity-when-launcher-icon-is-clicked

What are your thoughts on that? This feels like a hacky solution, and can't tell if it's react-native-navigation or react-native-notificaton

馃彋 stale

Most helpful comment

Adding android:launchMode="singleTask" to AndroidManifest.xml under MainActivity solved the issue for me.

All 7 comments

@miguelespinoza This is extremely helpful. My case is slightly different than yours. The splash activity appears forever (or until I press the back button). But your workaround seems to work.

The problem appears to be with react native navigation - I'm using a different library for notifications and I have the same problem. I'm not an android developer and therefore have no idea what are the consequences of it. Have you tested it thoroughly enough?

Hi @noambonnie, no consequences with this change. Simply if the Activity is not TaskRoot that means an Activity exists already that is TaskRoot. It's a safe solution, for a bug that's been existing since Android 1.0.

It definitely has been tested, it's been out in the wild with no side-effects reported from the fix 馃槃

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

The issue has been closed for inactivity.

Adding android:launchMode="singleTask" to AndroidManifest.xml under MainActivity solved the issue for me.

In my case android:launchMode="singleInstance" add to AndroidManifest.xml

It work for me ! 馃槅馃槅馃槅馃槅馃槅

In my case android:launchMode="singleInstance" add to AndroidManifest.xml

It work for me ! 馃槅馃槅馃槅馃槅馃槅

This work for me

Was this page helpful?
0 / 5 - 0 ratings