The Wayback Machine - https://web.archive.org/web/20201120153719/https://github.com/alibaba/ARouter/issues/774
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Autowired 失效没有获取的到参数的解决办法 #774

Closed
MySai opened this issue Dec 18, 2019 · 1 comment
Closed

@Autowired 失效没有获取的到参数的解决办法 #774

MySai opened this issue Dec 18, 2019 · 1 comment
Labels

Comments

@MySai
Copy link

@MySai MySai commented Dec 18, 2019

看了很多评论说什么名字错了什么。 我的情况应该有人遇到过
A类 withString("name", "android")

B类 @Autowired(name = "name")
public String name = "";
或者
@Autowired
public String name = "";

都获取不到参数但是 getIntent().getStringExtra("name")。 可以获取参数。弄得头疼,后面发现是因为初始化的问题 。模块化除了主 MyApplication 里
//Arouter 初始化
ARouter.init(application);
后面每个模块我都是父类写了
ARouter.getInstance().inject(this);
这样获取就没问题了

@zhi1ong
Copy link
Member

@zhi1ong zhi1ong commented Dec 24, 2019

inject 的原理就是在 .inject(this) 里面执行的赋值,自然要任何的 Activity 的 onCreate 都要调用这个 inject,最佳实践就是在 BaseActivity加

@zhi1ong zhi1ong added the 挺好 label Dec 24, 2019
@zhi1ong zhi1ong changed the title @Autowired 失效没有获取的到参数 @Autowired 失效没有获取的到参数的解决办法 Dec 24, 2019
@zhi1ong zhi1ong closed this Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.