dpa99c / react-native-launch-navigator

A React Native module for launching today's most popular navigation/ride apps to navigate to a destination.
143 stars 34 forks source link

Calling startActivity() #1

Closed TechNerdsUzi closed 6 years ago

TechNerdsUzi commented 6 years ago

i have an error while lunch google maps Error: Calling startActivity() from outside of an activity context requires the FLAG_ACTIVITY_NEW_TASK flag. is this really what you want ?

can you tell me how to fix this ?

dpa99c commented 6 years ago

I haven't encountered this problem in the example test project - have you tried building and running it?

And are you by any chance using react-native-navigation in your project? Since React Native is mono-activity by default, react-native-navigation is the most common way that multiple activities are introduced into React Native apps.

This SO answer indicates the quickest fix would be to set the FLAG_ACTIVITY_NEW_TASK flag on the intent, but I fear this would interfere with the history stack of react-native-navigation.

Currently this module uses the getReactApplicationContext() method of the ReactContextBaseJavaModule parent class to pass as context to the LaunchNavigator class for use in launch intents.

However, I will investigate if it's possible to obtain a reference to the current activity via the parent class, as I think passing the Activity context instead of the Application context would resolve this issue.

dpa99c commented 6 years ago

On further investigation, it's OK to use the FLAG_ACTIVITY_NEW_TASK flag because the intent launches another application so won't interfere with the history stack of the calling application. Therefore I'll commit a change to add this flag and publish a patch release.

dpa99c commented 6 years ago

The above commit is published in v1.0.1 Please let me know if that doesn't resolve your issue.