Mar*_*tin 8 android repository-pattern android-architecture-components
I would like to implement Repository
module to handle data operations. I have JSON file in row
directory and want create concrete Repository
implementation to get data from file. I'm not sure if I can use Context
as attribute in the constructor or method of Repository
.
e.g.
public class UserRepository {
UserRepository() {}
public List<User> loadUserFromFile(Context contex) {
return parseResource(context, R.raw.users);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为将上下文作为属性传递没有任何坏处。如果您不喜欢这个想法,那么您可以通过一种方便的方法检索上下文:Static way to get 'Context' on Android?
归档时间: |
|
查看次数: |
2598 次 |
最近记录: |