I am new to android development, please bear with me. I have three fragments - Frag1, Frag2 and Frag3. Frag1 is a sort of ListView having a list of items which is created when the App is launched. Frag2 and Frag3 basically correspond to VideoViews which will be used to play different videos from different players. One of them will play the content Video and the other will play Ad video.
When I click on a particular item in Frag1, I want to create both Frag2 and Frag3. I want to have both fragments since I might have to play the Ad at any time. I will hide the content Fragment when Ad is playing and Vice versa. Also I want that when back button is pressed, I should go back to Frag1 ( the listView), irrespective of whether Frag2 or Frag3 was visible when back button was pressed.
What I am not able to clearly figure out is how to stack the fragments so that whenever I press back button while playing either an Ad or video, it goes to the listView. Because if i understand correctly, the fragments get stacked up in the order they are added. So if I add in the order Frag1 followed by Frag2 and Frag3, then pressing back when Frag3 is on top will go to Frag2 rather than Frag1. Also say if currently Frag2 is visible and I press back, then I think Frag3 will still remain even though I want both Frag2 and Frag3 to get popped whenever I press back button.
Please help me regarding this. Any links which properly explains the concepts used here will also be appreciated.