ARouter学习及使用总结

router路由器的意思,ARouter是Android Router?(瞎猜的)

在Android开发中所谓的路由功能,就是我们常说的activity界面跳转,此时,你的脑海里是不是瞬间蹦出显式Intent和隐式Intent两种启动方式呢

显式Intent:

Intent intent= new Intent();
intent.setClass(this,xxx.class);
startActivity(intent);

存在类之间的直接依赖问题,耦合严重

隐式Intent:

AndroidManifest.xml中
<activity
    android:name=".MuBiaoActivity"
    android:exported="true"
    android:launchMode="singleTop">
        <intent-filter>
            <action android:name="test.Action" />
            <category android:name="android.intent.category.DEFAULT" /> 
        </intent-filter>
</activity>

启动Activity中
Intent intent = new Intent();
intent.setAction("test.Action");
startActivity(intent);

需要在配置清单中统一声明,会暴露,多模块开发协作也比较困难

两种方式startActivity后面的环节我们无法去控制,出现错误时候就无能为力了。

ARouter可以在没有依赖的的情况下进行界面跳转。

GitHub:https://github.com/alibaba/ARouter/blob/master/README_CN.md

详细使用教程👆

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android ARouter 是一个用于实现组件化、模块化开发的路由框架,它提供了一种简单的方式来实现不同组件之间的跳转和通信。 使用 ARouter 的步骤如下: 1. 在项目的 build.gradle 文件中添加依赖: ```groovy implementation 'com.alibaba:arouter-api:x.x.x' annotationProcessor 'com.alibaba:arouter-compiler:x.x.x' ``` 请将 `x.x.x` 替换为最新的版本号。 2. 在需要使用 ARouter 的模块中,创建一个类似于 Application 的类,并在其 `onCreate()` 方法中进行 ARouter 的初始化: ```java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) { ARouter.openLog(); ARouter.openDebug(); } ARouter.init(this); } } ``` 3. 在需要跳转到的目标页面中,使用 `@Route` 注解进行标记,以便 ARouter 进行识别: ```java @Route(path = "/path/to/target") public class TargetActivity extends AppCompatActivity { // ... } ``` 4. 在需要跳转的地方,通过调用 `ARouter.getInstance().build("/path/to/target").navigation()` 来实现页面跳转: ```java ARouter.getInstance().build("/path/to/target").navigation(); ``` 5. 如果需要传递参数,可以使用 `withXxx` 方法来添加参数: ```java ARouter.getInstance() .build("/path/to/target") .withString("key", "value") .navigation(); ``` 通过以上步骤,你就可以在 Android 项目中使用 ARouter 进行页面跳转和参数传递了。当然,ARouter 还提供了其他功能,比如拦截器、URI 跳转等,你可以根据具体需求进行使用。希望对你有所帮助!如果还有其他问题,请继续提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值