I am trying to build a delivery app. I have a list of products to choose from. After the user selects a product then he is lead to a series of stages to define extras and options of a certain product.
List of products:
Then, Lets say someone clicks on one of the products, we go to the controller FragmentActivity:
The subtotal at top and the button at the bottom of the page belongs to the fragment activity. Then I place a group of radio buttons at the center layout. Everything is fine till now. Click on the button leads for the replacement of the fragment:
Everything is beautiful until now. I can access the buttons and the subtotal through the fragments. However, if I press the back button on the device it leads me back to the list of products and not to the previous fragment. Even if I manage to go back to the previous fragment it would lose the radiobutton selection as well.
Then the next fragment is a calculation of the products and its extras:
When I press the button, I just use finish() in the fragment and it leads me back to the list of products which is my desired result. However, I need to know that I am coming from there in the list of products so I can add that product to the shopping cart that is being built for the delivery order.
I am really new in using fragments, but I can pass arguments just fine. What I am struggling is to control the navigation of the fragments through the FragmentActivity that controls the fragments. Also, I am struggling to keep the states of the fragments (remembering user input). At last, I need to go back to the list of products with a result of that item that was being constructed so I can add it to the shopping cart.
Am I going to the right direction? How can I implement these features(navigation, fragment state, returning to previous activity with some data since I just use finish()), Many thanks guys!