Display Distinct Fragment instances as “Pop Ups” or Dialog in an Activity, Edit their Components, Close them, and Repeat

Solution for Display Distinct Fragment instances as “Pop Ups” or Dialog in an Activity, Edit their Components, Close them, and Repeat
is Given Below:

I am new to Android Studio and I’d like some advice on a better way to code a fragment to “pop” open when a button is clicked in the host activity, allow the user to adjust Seekbars, and then close (preserving the changes) when a return button is clicked (and perhaps when the user clicks outside of the fragment?)

Activity Diagram mock up

For now, each instance of fragment C is coded in the host activity’s layout xml like this:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TrackerActivity">


<!-->[code for other components removed for sake of brevity]<-->


<fragment
        android:id="@+id/showCmdrDmgP1"
        android:name="com.example.magicapplication.CmdrFrag"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginTop="100dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="100dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout="@layout/fragment_cmdr" />

Here’s the OnCreate method for the host activity:

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tracker);
        fragmentManager = this.getSupportFragmentManager();


        /* findViewById statements removed for brevity */

//These are the instances of "Fragment A" in the linked diagram

        ArrayList<Fragment> frags = new ArrayList<Fragment>(Arrays.asList(player1, player2, player3, player4, player5, player6));
//These are the instances of "Fragment B" 

        ArrayList<Fragment> manaFrags = new ArrayList<Fragment>(Arrays.asList(manaP1, manaP2, manaP3, manaP4, manaP5, manaP6));

//These are the Buttons that open instances of Fragment C

        ArrayList<ImageButton> ibCmds = new ArrayList<>(Arrays.asList(ibCmd, ibCmd2, ibCmd3, ibCmd4, ibCmd5, ibCmd6));

//These are the instances of Fragment C, the "pop up" in question

        ArrayList<Fragment> cmdrFrags = new ArrayList<>(Arrays.asList(cmdrP1, cmdrP2, cmdrP3, cmdrP4, cmdrP5, cmdrP6));

        /* Excluded code adjusting the number of fragments based on user input from a previous activity */

        life = getIntent().getIntExtra("life", 20);
        int[] colors = getApplicationContext().getResources().getIntArray(R.array.tracker_colors);
        for(int p =0; p<frags.size(); p++){
            ((LifeFrag) frags.get(p)).updateLife(life);
            frags.get(p).getView().setBackgroundColor(colors[p]);
            manaFrags.get(p).getView().setBackgroundColor(colors[p]);
            int finalP = p;
            ibCmds.get(p).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    FragmentTransaction ft = fragmentManager.beginTransaction();
                    ft.show(cmdrFrags.get(finalP));
                    ft.commit();
                }
            });
        }
    }

I don’t think this a very good solution.

Furthermore, I’d like to give the user the option to add additional CardViews to the fragment. That seemed pretty simple, but when I tested out an implementation of this (which I’ve since removed the code for), the fragment did not scale inside the “window” I allotted it in the xml.

I considered using a DialogFragment, but it seems like retaining each fragment separately could be a problem…?
I’ve also seen some threads here where answers warned against using the PopUpWindow class for similar use cases because of possible memory leak.

Thank you!