You can try to remove the fragment after you have send the mail(fixed):
getActivity().getSupportFragmentManager().beginTransaction().remove(MailFragment.this).commit();
But remember that it can be removed only if it was added dynamically using FragmentTransaction
and the .add()
method. If the fragment was added in XML, remove method won't work.
To add a fragment dynamically you should do this:
MailFragment mailFragment = new MailFragment();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.containerForFragments, mailFragment).commit();
Then you can remove this fragment via the .remove()
method.
By the way instead of removing the fragment you can try just hide it (will not be removed from memory):
getActivity().getSupportFragmentManager().beginTransaction().hide(MailFragment.this).commit();