You're likely running into the same problem from #355 where a Chrome custom tab (web browser) is launched from your app's Stripe flow, like to perform 3DSecure confirmation, and if the app is backgrounded, that web browser gets killed.
If your Android launchMode
is set to singleTask
(check your AndroidManifest.xml
), that's why this is occurring. Unfortunately, this is not addressable by the Stripe React Native library.
Luckily, @stianjensen shared a fix in the above Github issue. It is summarized here:
- Modify your
MainApplication
:
public class MainApplication extends Application {
+ private ArrayList<Class> runningActivities = new ArrayList<>();
+ public void addActivityToStack (Class cls) {
+ if (!runningActivities.contains(cls)) runningActivities.add(cls);
+ }
+ public void removeActivityFromStack (Class cls) {
+ if (runningActivities.contains(cls)) runningActivities.remove(cls);
+ }
+ public boolean isActivityInBackStack (Class cls) {
+ return runningActivities.contains(cls);
+ }
}
- create
LaunchActivity
+ public class LaunchActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ BaseApplication application = (BaseApplication) getApplication();
+ // check that MainActivity is not started yet
+ if (!application.isActivityInBackStack(MainActivity.class)) {
+ Intent intent = new Intent(this, MainActivity.class);
+ startActivity(intent);
+ }
+ finish();
+ }
+ }
- Modify
AndroidManifest.xml
and moveandroid.intent.action.MAIN
andandroid.intent.category.LAUNCHER
from your.MainActivity
to.LaunchActivity
+ <activity android:name=".LaunchActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
...
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
...
- Modify
MainActivity
to look something like the following (you likely already have anonCreate
method that you need to modify):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
((BaseApplication) getApplication()).addActivityToStack(this.getClass());
}
@Override
protected void onDestroy() {
super.onDestroy();
((BaseApplication) getApplication()).removeActivityFromStack(this.getClass());
}