Fragment is added to the activity using Add and hide instead of replace, and if the screen rollover may add a new fragment in, it will be ghosting.
If you have a Sparsearray save fragment, you should use it when initializing
Private voidinitfragment (Bundle savedinstancestate) {//Set up Fragments//fragments.append (Main_index, Mainfragment.newinstance ());//fragments.append (Success_index, Successfragment.newinstance ());//fragments.append (Failed_index, Failedfragment.newinstance ());//fragments.append (None_index, Nonefragment.newinstance ());Fragments =NewSparsearray<>(); //Main FragmentFragment mainfragment =Getsupportfragmentmanager (). Findfragmentbytag (String.valueof (Main_index)); if(Mainfragment = =NULL) {mainfragment=mainfragment.newinstance (); } fragments.append (Main_index, mainfragment); //Success FragmentFragment succcessfragment =Getsupportfragmentmanager (). Findfragmentbytag (String.valueof (Success_index)); if(Succcessfragment = =NULL) {succcessfragment=successfragment.newinstance (); } fragments.append (Success_index, succcessfragment); //Failed FragmentFragment failedfragment =Getsupportfragmentmanager (). Findfragmentbytag (String.valueof (Failed_index)); if(Failedfragment = =NULL) {failedfragment=failedfragment.newinstance (); } fragments.append (Failed_index, failedfragment); //None FragmentFragment nonefragment =Getsupportfragmentmanager (). Findfragmentbytag (String.valueof (None_index)); if(Nonefragment = =NULL) {nonefragment=nonefragment.newinstance (); } fragments.append (None_index, nonefragment); //Add to Activity for(inti =0; I < fragments.size (); i++) {Fragment F=fragments.valueat (i); if(!f.isadded ()) Getsupportfragmentmanager (). BeginTransaction () . Add (R.id.container, F, string.valueof (Fragments.keyat (i))). Hide (f). Co Mmit (); } }
Do not directly append the new fragment, but through Fragmentsupportmanager first check whether there are existing fragment, so you can solve the ghosting problem.
It is important to note that setretaininstance (true) must be set so that fragment is not destroyed in the manager and the data is not nullpointerexception error after replacing fragment
Multiple fragment on screen rollover will resolve the problem of ghosting