目录
1. 通过ARouter获取服务,得到公共数据
val vehicleId = getAService<VehicleDataService>()?.curVehicle?.value?.id
interface VehicleDataService : IProvider {
/** 当前车辆. */
val curVehicle: LiveData<Vehicle?>
}
@Route(path = ARouters.Vehicle.SERVICE)
class VehicleDataServiceImpl : VehicleDataService() {
private val _curVehicle by lazy { MutableLiveData<Vehicle?>() }
override val curVehicle: LiveData<Vehicle?>
get() = _curVehicle
}
/**
* 获取服务.
* @return T?
*/
inline fun <reified T : IProvider> getAService(): T? =
ARouter.getInstance().navigation(T::class.java)
2. 通过ARouter跳转Activity
ARouter.getInstance()
.build(ARouters.Vehicle.VEHICLE_NORMAL_HELP)
.navigation()
object ARouters {
object Vehicle {
const val VEHICLE_NORMAL_HELP = "/vehicle/normal_help"
}
object ExtraKeys {
}
}