https://gitee.com/mirrors/ARouter?_from=gitee_search
1添加依赖
javaCompileOptions {
annotationProcessorOptions {
arguments = [moduleName :project.getName() ]
} }
compile'com.alibaba:arouter-api:1.3.1'
annotationProcessor'com.alibaba:arouter-compiler:1.1.4'
2起始activity
package com.example.arouter;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.myapplication.R;
@Route(path = "/app/ArouterActivity")
public class ArouterActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_arouter);
ARouter.getInstance().inject(this);
}
public void go(View view) {
ARouter.getInstance().build(Constance.DeatailActivityURL)
.withString("name","wy")
.withInt("age",6)
.navigation();
}
}
3目标activity
package com.example.arouter;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.myapplication.R;
@Route(path = Constance.DeatailActivityURL)
public class ArouterDetailActivity extends AppCompatActivity {
@Autowired
public String name;
@Autowired
public int age;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_arouter_detail);
ARouter.getInstance().inject(this);
Log.e("wy", "onCreate: "+name+" age:"+age );
}
}
4url池塘
package com.example.arouter;
public class Constance {
public static final String DeatailActivityURL="/app/ArouterDetailActivity";
}
|