当前位置:网站首页>Use of arouter

Use of arouter

2022-07-04 14:16:00 Novice Xiaowang

  One for help  Android App  The framework for component transformation     Support routing between modules 、 signal communication 、 decoupling 

1. Basic use :

defaultConfig {
    applicationId "com.example.greendao"
    minSdk 29
    targetSdk 31
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     To configure 
    javaCompileOptions {
        annotationProcessorOptions {
            arguments = [AROUTER_MODULE_NAME: project.getName()]
        }
    }
}
dependencies {
    implementation 'com.alibaba:arouter-api:1.5.2'
    annotationProcessor 'com.alibaba:arouter-compiler:1.5.2'}

2. initialization

stay application in

ARouter.init(this);

3. Use

It's about to jump activity On the configuration Route annotation  

@Route(path = "/test/MainActivity2")

Jump code  

ARouter.getInstance().build("/test/MainActivity2")  The interface to jump to 
        .withString("name","eeeeee")
        .withString("age","30").navigation(); Parameters carried 

4. Data analysis Automatic data injection  

@Route(path = "/test/MainActivity2")
public class MainActivity2 extends AppCompatActivity {
    @Autowired(name = "name")
    String name;
    @Autowired(name = "age")
    String age;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ARouter.getInstance().inject(this);
        Log.e("MainActivity2",name+age);
    }

Official instructions for use :gARouter: ARouter Alibaba open source Android Routing middleware , It's used for page 、 Services provide routing capabilities (gitee.com)

原网站

版权声明
本文为[Novice Xiaowang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041140542517.html

随机推荐