简体   繁体   中英

Android | Fragment navigation triangle

I have what I think is a relatively simple problem. I got just one activity with three fragments in it (showing only one at a given time). So, these are my fragments

  1. ORDERS (shows a list of orders)
  2. ORDER DETAILS
  3. NEW ORDER (shows a form to create a new order)

OK so, I guess we all know what the navigation between these should be. I'm having some problems with back navigation though. Here's what happens.

1 -> 3 -> 2 [<] nothing happens [<] goes back to android :/

*[<] = [user presses back key].

I've been doing some research and I know there are some methods I should be using, among them:

.add .replace transaction.addToBackStack(null)

(I don't quite understand what that last one is doing but it seems to save the transaction so I can get back, which would be the same ass .add?).

Thanks and leave any comments below I can add any relevant information should it be needed.

The difference between add() and replace() is that replace() removes the fragment in the container and then add the new fragment into it while add() just adding. If you want to navigate between fragments, you should use addToBackStack().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM