androidconductor

Conductor: navigate to a Controller without adding it to backstack


I am implementing some navigation with Conductor library. So basically, from a certain Controller, no matter how far I navigate from it, on the back press, I want to be able to return to it (from any further Controller). Now I tried to do something like:

router.backstack.remove(router.backstackSize)

onCreateView for new controller, as I thought, to remove the newly added controller, but that does not work.


Solution

  • One of the easy ways to do this is to use something like router.popToTag(controller.tag()) which will pop any controllers off of the backstack that are on top of the controller.

    The other way, if this is going to be the bottom most controller is to use router.setRoot(...) in your Activities controller. (router.hasRootController() can let you know if this has already been done) Then returning to "home" is just a matter of router.popToRoot()