【发布时间】:2020-01-19 11:38:30
【问题描述】:
我正在使用 Room 来实现数据库,使用数据库的代码位于 Repository 中,要获取数据库 Repository 的实例需要 Application 作为类属性,我想在扩展 IntentService 的类和类中获取 Repository 的实例扩展了 Worker 类,现在,他们不需要 Application 作为属性,但是为了能够在其中使用 Repostiory 我必须添加它,这是一种好的编程习惯吗?也许其他一些解决方案?
public class SunshineSyncIntentService extends IntentService {
private Application mApplication;
public SunshineSyncIntentService(@NotNull Application application) {
super("SunshineSyncIntentService");
mApplication = application;
}
@Override
protected void onHandleIntent(Intent intent) {
SunshineSyncTask.syncWeather(mApplication);
}
}
【问题讨论】:
标签: android repository android-room android-context