Android - Temporal & Ancestral Navigation with ViewPager & Fragments

Posted by rascuache on Stack Overflow See other posts from Stack Overflow or by rascuache
Published on 2012-09-21T06:39:46Z Indexed on 2012/09/24 3:37 UTC
Read the original article Hit count: 297

I'm trying to work out the best way to implement the 'ancestral' and 'temporal' navigation (utilising the up button and back buttons), for a music player I'm working on.

Currently, the user is presented with a viewpager, and can page between three main fragments (ArtistMain, AlbumMain and SongMain). Upon choosing an item inside that view, a fragment transaction occurs, and the viewpager goes out of view, replaced by a new fragment (AlbumSub, Songsub or player, depending on where the user came from). The user can then navigate deeper, until a song is chosen, and then they are taken to the 'player' screen.

I guess the question is: How do I implement all of this conditional navigation?

I'm fairly new to android and programming in general, and I just can't seem to come up with an efficient way to achieve this. At the moment, as each fragment is brought into view, the app is checking to see where the user just came from, and then determines where the user should be taken if back or home is called. This means I have a booleans like "fromArtistMain", "fromAlbumSub", and I'm checking for things like "fromSongSub && fromPlayer".. it's all turning into a bit of a mess.

I've drawn a diagram (in paint, sorry!!), to depict the navigation I'm trying to achieve. The yellow represents the 'up' button press, the red is the 'back' button press, and blue is just normal navigation. The green arrows are meant to represent the view paging:

Navigation Diagram

Any advice is welcome. It might take something really simple that I've just overlooked.

Thanks for your time.

© Stack Overflow or respective owner

Related posts about android

Related posts about navigation