I am trying to implement the technical support function of users of my application by sending a description of the problem using a third-party email application. It is expected that it should work like this:
- In the "More" fragment there is a menu item "Support":
- Clicking this item opens the fragment "Support", in which the user spends a description of his problems with the application. After that he clicks the "Submit" button:
This leads to the opening of a third-party mail android application with which the user sends a description of the problem to us.
After sending the letter, this application closes and returns to the “More” fragment in my application:
But at the last step, some kind of failure occurs and instead of the expected fragment I see it with the “Support” fragment superimposed on top:
At the same time, the “More” fragment is in focus, the logs show that all the methods of the life cycle of the “Support” fragment have been called before its destruction and disconnection from activation (onDetach ()), and when switching to any fragments, the overlay is saved:
This is implemented as follows:
The "More" fragment is implemented in the Frag5More.java class:
public class Frag5More extends MvpAppCompatFragment implements Frag5MoreView { @InjectPresenter Frag5MorePresenter mThisPresenter; @BindView(R.id.lvMore) ListView lvMain; private FragmentManager mFm; private AdapterView.OnItemClickListener lvMainOnItemClickListener = new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentTransaction ftrans = mFm.beginTransaction(); switch (position) { case 0: ftrans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .replace(R.id.rlContent, new Frag5MoreAccount()) .addToBackStack("Frag5MoreAccount") .commit(); break; case 1: ftrans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .replace(R.id.rlContent, new Frag5MoreHelp()) .addToBackStack("Frag5MoreHelp") .commit(); break; case 2: ftrans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .replace(R.id.rlContent, new Frag5MoreSupport()) .addToBackStack("Frag5MoreSupport") .commit(); break; } } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFm = getActivity().getSupportFragmentManager(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.frag5_more, container, false); ButterKnife.bind(this, rootView); if(mThisPresenter.getMenu().size() == 0) mThisPresenter.createMenu(getContext()); MoreListAdapter boxAdapter = new MoreListAdapter( getActivity().getBaseContext(), mThisPresenter.getMenu()); lvMain.setAdapter(boxAdapter); lvMain.setOnItemClickListener(lvMainOnItemClickListener); return rootView; } The support fragment is implemented in the Frag5MoreSupport.java class:
public class Frag5MoreSupport extends MvpAppCompatFragment { private final static String LOG_TAG = "Frag5MoreSupport"; @BindView(R.id.message) EditText message; private FragmentManager mFm; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Logger.writeString(LOG_TAG, "onCreate"); setHasOptionsMenu(true); if (getActivity() != null) { ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); getActivity().setTitle(getString(R.string.more_support)); ((InputMethodManager) (getActivity()).getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } setCurFragContext(getContext()); this.mFm = getActivity().getSupportFragmentManager(); } @SuppressLint("NewApi") public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logger.writeString(LOG_TAG, "onCreateView"); View rootView = inflater.inflate(R.layout.frag_support, container, false); ButterKnife.bind(this, rootView); message.requestFocus(); return rootView; } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.tt_menu, menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { Logger.writeString(LOG_TAG, "onOptionsItemSelected"); switch (item.getItemId()) { case R.id.send: String mailto = App.SUPPORT_EMAIL + "?cc=" + "" + "&subject=" + Uri.encode(getString(R.string.app_name)) + "&body=" + Uri.encode(message.getText().toString()); Intent emailIntent = new Intent(Intent.ACTION_SENDTO); emailIntent.setData(Uri.parse(mailto)); try { Logger.writeString(LOG_TAG, "startActivity for send e-mail"); startActivity(emailIntent); Logger.writeString(LOG_TAG, "closeActivity after send e-mail"); } catch (ActivityNotFoundException ignored) { Logger.writeStackTrace(LOG_TAG, ignored.getStackTrace()); ignored.printStackTrace(); } KeyboardsController.hideKeyboard(getActivity()); mFm.popBackStackImmediate(); return true; case android.R.id.home: mFm.popBackStackImmediate(); return true; default: return super.onOptionsItemSelected(item); } } At the same time, it was experimentally established that the placement of instructions
mFm.popBackStackImmediate(); even before the call of intention, even after it, even though the removal of this call asynchronous does not affect in any way what happened.
How to get rid of overlay fragments after calling a third-party android application?




<RelativeLayout android:id="@+id/rlContent" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/bottom200">No effect expected. - Noname Noferstname