Dan
Dan

Reputation: 8834

Linking.getInitialURL constantly being executed and app being duplicated

Sorry for the long winded title.

Here's my componentDidMount() function

componentDidMount() {
  Linking.getInitialURL().then(data => {
    console.log(data);
  });
}

When I boot up my app, data is rightfully set to null.

A User then logs in via Google Chrome which is opened via

Linking.open('https://...);

When the User gets redirected back to my app, I can see that data has been populated. This is all well and good.

However, when I am redirected back, I see duplicate components. Here's a screenshot from the React Native Debugger. I have <AppContainer root=1..> and <AppContainer root=11..>

enter image description here

Because of this duplication, my app calls componentDidMount() twice and Linking.getInitialURL() is called multiple times.

Furthermore, if I refresh the app via the developer menu, the data returned from Linking.getInitialURL's promise is still populated when it should be null.

Upvotes: 1

Views: 1901

Answers (1)

Dan
Dan

Reputation: 8834

The solution to this problem was to add android:launchMode="singleTask" to my .MainActivity activity.

Solution found on this Github thread.

Upvotes: 3

Related Questions