package com.braintreepayments.browserswitch.demo;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

public class DemoActivity extends FragmentActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(android.R.id.content, new DemoFragment())
                    .commit();
        }
    }
}

@@ -154,16 +154,62 @@
 ctivity;
+%0Aimport androidx.fragment.app.FragmentManager;
 %0A%0Apublic
@@ -256,16 +256,100 @@
 vity %7B%0A%0A
+    private static final String FRAGMENT_TAG = DemoFragment.class.getSimpleName();%0A%0A
     @Ove
@@ -478,81 +478,130 @@
     
-if (savedInstanceState == null) %7B%0A            getSupportFragmentManager()
+FragmentManager fm = getSupportFragmentManager();%0A        if (fm.findFragmentByTag(FRAGMENT_TAG) == null) %7B%0A            fm
 .beg
@@ -681,16 +681,30 @@
 agment()
+, FRAGMENT_TAG
 )%0A      

improve the fix to avoid adding multiple DemoFragments