//传递方式使用Bundle传递数据
//List值说明
val data = ArrayLis<CartProduct>()
//CartProducty对象实现Serializable接口
@JsonClass(generateAdapter = true)
data class CartProduct(
val currencySymbol: String,
@Json(name = "count")
var count: Int = 0,
@Json(name = "code")
val productId: String,
@Json(name = "img")
val productImg: String,
@Json(name = "name")
val productName: String,
@Json(name = "price")
val productPrice: Double,
var checked: Boolean = false
) : Serializable
//构建Bundle
val bundle=bundleOf(“data_list” to data )
ARouter.getInstance().build(path).with(bundle) .navigation(context)
//获取数据
@Autowired(name = “data_list”)
@JvmField
var products: List<CartProduct>? = null
//此时获取到的products为null
//ARouter生成代码
public class OrderConfirmActivity$$ARouter$$Autowired implements ISyringe {
private SerializationService serializationService;
@Override
public void inject(Object target) {
serializationService = ARouter.getInstance().navigation(SerializationService.class);
OrderConfirmActivity substitute = (OrderConfirmActivity)target;
substitute.isEdit = substitute.getIntent().getBooleanExtra("isEdit", substitute.isEdit);
if (null != serializationService) {
substitute.products = serializationService.parseObject(substitute.getIntent().getStringExtra("Products"), new com.alibaba.android.arouter.facade.model.TypeWrapper<List<CartProduct>>(){}.getType());
} else {
Log.e("ARouter::", "You want automatic inject the field 'products' in class 'OrderConfirmActivity' , then you should implement 'SerializationService' to support object auto inject!");
}
}
}
debug发现serializationService 为null
不使用@Autowired(name = “data_list”)取值换为手动解析Intent
val products= intent.getSerializableExtra( “data_list”) as List<CartProduct>
此时值不为空数据获取成功
1条答案
按热度按时间svdrlsy41#
我使用Gson解析,这样做可以。