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

ViewModelProvider(this).get(MyViewModel::class.java) #21

Closed
d8txc opened this issue Oct 21, 2021 · 2 comments
Closed

ViewModelProvider(this).get(MyViewModel::class.java) #21

d8txc opened this issue Oct 21, 2021 · 2 comments

Comments

@d8txc
Copy link

d8txc commented Oct 21, 2021

//注:不能使用new 关键字创建MyViewModel对象,否则MyViewModel感知不到生命周期
val viewModel = ViewModelProvider(this).get(MyViewModel::class.java)
大神请教,viewModel的创建,在kt下如上写法,在java下必须要new,上述说不能使用new,请问java下viewModel如何创建?

@liujingxing
Copy link
Owner

我的意思是不能new MyViewModel()ViewModelProvider Java的话该怎样就怎样

@d8txc
Copy link
Author

d8txc commented Oct 21, 2021

OK, 明白了,文件理解有误,谢谢大神解答!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants