S
S
Sergey Shilovsky2018-12-22 12:07:36
Android
Sergey Shilovsky, 2018-12-22 12:07:36

What is the correct way to navigate backwards between fragments?

There are several fragments, among them - authorization (A) and profile (B). When the user logs in, I replace A with B without adding it to the backstack so that backPress cannot return to authorization. The remaining fragments are added to the stack. As a result, with backPress, frag B is not deleted, but remains behind the fragment that preceded A.
I have a couple of solutions:
1) Search by tag / id for a fragment where it should not be and delete
2) Make the background of all fragments opaque, then it will remain, but it will not be visible
Why this happens, I understand, with the backPress FragmentManager trying to delete A, but it is no longer
there.I would like to know how to handle it in the right way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Varakosov, 2018-12-22
@First_Spectr

There is a simple approach to this issue. When you need authorization, you use startActivityForResult() to launch an activity with fragment A (for which the NO_HISTORY and SECURE flags are registered), and catch its result.
Stop using fragments with or without reason, they are designed to make your life easier, not create new problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question