A tiny Android library for testable navigation logic
- A Route is a simple abstraction of Android's Intent class.
- Routes can be created with a set of parameters, just like a Bundle.
- Routes don't depend on the Android framework, so they can be used in unit tests
// create a route with parameters
val route = Route.to(DestinationActivity::class.java)
.param("foo", 123)
.param("bar", true)
.create()
// launch the route directly
startActivity(route)
// or convert to an Intent
val intent = intentFor(route)
startActivity(intent)
// access params directly from the Intent
val foo = intent?.extras?.getInt("foo")
val bar = intent?.extras?.getBoolean("bar")
// or use the withParams() extension
withParams {
val foo = getInt("foo")
val bar = getBoolean("bar")
}
You can find an example of using Routes and testing them in the sample project.
Routes is available on JitPack. To include it in your project, add the following line to your build.gradle
:
dependencies {
implementation 'com.github.greghynds:routes:1.0.0'
}
The project can be built by navigating to the root directory and running:
./gradlew clean build
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Apache License 2.0