setContentView(R.layout.activity_one);
}
}
第二步:调用 navigation 方法实现跳转
ARouter.getInstance().build(ARouterConstants.COM_ACTIVITY1).navigation();
这样,从 A 跳转到 B 的功能便实现了。
传递参数
Arouter 的跳转页非常简单,我们可以调用 PostCard 的 withX 等方法传递相应的参数
比如,我们想传递 String,可以调用 withString,想传递 int,可以调用 withInt ,想传递 Parceable 对象,可以调用 withParcelable。
ARouter.getInstance().build(ARouterConstants.COM_PARSE_ACTIVITY).withString(NAME,“jun”)
.withInt(AGE,1).withParcelable(PERSON,person).withObject(TEST_OBJ,testObj)
同时 ARouter 还支持传递 Object 对象,只需调用 withObject 方法,同时需要在我们的 moudle 下面增加相关的类。实际上,它的原理是通过将 object 转化成 String,然后存进 intent 中,在解析参数的时候,再通过相应的 key 去除 String,然后转化成 object。
如果你的项目使用的是 Gson,那可以使用下面的类
@Route(path = “/service/json”)
public class JsonServiceImpl implements SerializationService {
private Gson mGson;
@Override
public void init(Context context) {
mGson = new Gson();
}
@Override
public T json2Object(String text, Class clazz) {
checkJson();
return mGson.fromJson(text, clazz);
}
@Override
public String object2Json(Object instance) {