您好,欢迎来到尔游网。
搜索
您的当前位置:首页组件化ARoute使用总结

组件化ARoute使用总结

来源:尔游网


项目结构

app为壳,commonlib为公共组件库,chat,home等为模块

gradle配置

gradle.properties里配置组件化开关

#isNeedHomeModule=true
isNeedHomeModule=false
#isNeedChatModule=true
isNeedChatModule=false
#isNeedFindModule=true
isNeedFindModule=false
#isNeedMineModule=true
isNeedMineModule=false

app的gradle里配置依赖

dependencies {
   if (isNeedHomeModule.toBoolean()) {
        implementation project(':home')
    }
    if (isNeedFindModule.toBoolean()) {
        implementation project(':find')
    }
    if (isNeedChatModule.toBoolean()) {
        implementation project(':chat')
    }
    if (isNeedMineModule.toBoolean()) {
        implementation project(':mine')
    }
    implementation project(':commonlib')
}

chat模块目录
if (!isNeedChatModule.toBoolean()) {
    apply plugin: 'com.android.application'
} else {
    apply plugin: 'com.android.library'
}
defaultConfig {
        if (!isNeedChatModule.toBoolean()) {
            applicationId "tsou.cn.module_chat"
        }
        sourceSets {
            main {
                if (!isNeedChatModule.toBoolean()) {
                    manifest.srcFile  'src/main/manifest/AndroidManifest.xml'
                } else {
                    manifest.srcFile  'src/main/AndroidManifest.xml'
                }
       }
}

区分清单文件,别忘了在注册application同时初始化ARouter

跳转

传值

ARouter.getInstance().build("/chat/main")
                        .withLong("key1", 123)
                        .withString("key3", "456")
                        .navigation();

接收,Route注解注册路径,Autowired注解传递参数

@Route(path = "/chat/main")
public class MainActivity extends AppCompatActivity {

    private TextView text;

    @Autowired
    public String key3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ARouter.getInstance().inject(this);
        Toast.makeText(this, "收到传送过来的数据:" + key3, Toast.LENGTH_LONG).show();
        text = findViewById(R.id.text);
        text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- axer.cn 版权所有 湘ICP备2023022495号-12

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务