Skip to content

Magellan vs. Jetpack Navigation with Safeargs

Ryan Moelter edited this page Dec 2, 2021 · 1 revision

This is a work in progress, and we'll update the associated issue when it's done.

Context

Disclaimer: we are not as experienced with Jetpack Navigation as we are with Magellan, so if any of this information is inaccurate, please create an issue.

Magellan focuses on simplicity, flexibility, practicality, and testability, and makes some opinionated design choices. Jetpack Navigation, on the other hand, has to appeal to a broader range of developers and use cases in order to be Google’s official solution.

Advantages of Magellan

  • Typesafe page parameters with no compiler plugin
  • Dynamic navigation routes
    • Implicitly defined when navigating, instead of XML-defined as required by the safeargs plugin
    • Allows for more flexible navigation and quicker iteration
  • Composition of Steps/Journeys allowing for breaking down complex pages into smaller components (see LifecycleAware and "child" components)
  • Compile-time validation that navigation is possible (i.e. Magellan uses objects instead of String or Int route identifiers)
  • Steps/Journeys are easier to test and mock/fake/stub dependencies, since they're regular Java objects that can be directly instantiated

Advantages of Jetpack Navigation with Safeargs

  • All routes are declared at compile time (because of Safeargs, they need to be defined in XML)
    • Allows for more controlled navigation
  • Graphical editor for the XML route definitions
  • Officially supported by Google and widely used by the community

Some use cases not supported by Magellan (yet)

Requiring one of these would obviously be a reason to choose Jetpack Navigation. Feel free to contribute features to handle these cases, but please consider creating an issue or a small prototype to validate your approach with the core maintainers first.

  • Automatic state restoration after process death: To avoid making everything Parcelable, we keep the state at the Application level, but that also means that whenever the Application is destroyed, all navigation and view state is lost.