Router is a Android library which provides routing features to your applications.
In your module build.gradle :
dependencies {
implementation "com.chargemap.android:router:latestVersion"
}
object Routes {
object Second : Route(path = "/second")
object Third : RouteWithParam<Third.Bundle>(path = "/third") {
@Parcelize
class Bundle(
val text: String
) : RouteParam
}
}
Routes.Second.register {
Intent(it, SecondActivity::class.java)
}
or even simpler:
Routes.Second.register<SecondActivity>()
You are free to initialize your routes wherever you want but be sure to do it before pushing the associated route.
You may use App Startup or the onCreate function of a custom application registered in your manifest (see sample).
You can push a new route from either an Activity or a Fragment
For a simple route :
Router.of(this)
.push(
Routes.Second
)
For a route with a param :
Router.of(this)
.push(
Routes.Third,
Routes.Third.Bundle(
text = "Hello"
)
)
This library is inspired from florent37/Navigator
Chargemap | Author |
---|