在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Router开源软件地址:https://gitee.com/chenenyu/Router开源软件介绍:
Router中文wiki. 方便的话给个star!❤️ Getting startedBranch 1.5 see here
buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:+' classpath "com.chenenyu.router:gradle-plugin:版本号" }} latest
apply plugin: 'com.android.application' // apply plugin: 'com.android.library'apply plugin: 'com.chenenyu.router' 注意: 在rootProject的 ext { routerVersion = 'x.y.z' compilerVersion = 'x.y.z'} latest latest 基本用法
@Interceptor("SampleInterceptor")public class SampleInterceptor implements RouteInterceptor { @Override public RouteResponse intercept(Chain chain) { // do something return chain.process(); }}
// 给Activity添加注解,指定了路径和拦截器(可选)@Route(value = "test", interceptors = "SampleInterceptor")public class TestActivity extends AppCompatActivity { @InjectParam(key="foo") // 参数映射 String foo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Router.injectParams(this); // 自动从bundle中获取并注入参数 ... }}// 给Fragment添加注解@Route("test")public class TestFragment extends Fragment { ...}
// 简单跳转Router.build("test").go(this);// startActivityForResultRouter.build("test").requestCode(0).go(this);// 携带bundle参数Router.build("test").with("key", Object).go(this);// 添加回调Router.build("test").go(this, new RouteCallback() { @Override public void callback(RouteStatus status, Uri uri, String message) { // do something }});// 获取路由对应的intentRouter.build("test").getIntent();// 获取注解的FragmentRouter.build("test").getFragment(); 进阶用法建议浏览 wiki. 谁在使用Router讨论QQ group: 271849001 Donate ❤️License |
请发表评论