Java tutorial
//package com.java2s; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; public class Main { public static void removeFragment(Activity activity, Fragment fragment) { if (activity != null) { try { FragmentManager fragmentManager = activity.getFragmentManager(); fragmentManager.executePendingTransactions(); if (fragment.isAdded()) { FragmentTransaction ft = fragmentManager.beginTransaction(); ft.remove(fragment); ft.commitAllowingStateLoss(); fragmentManager.executePendingTransactions(); } } catch (Exception e) { } } } }