问题:
My Fragment仅在第二次调用时获取数据(例如,当我旋转屏幕时) .
在我看来,这些代码行是repo类中的问题:
public class UserRepository {
private Webservice webservice;
// ...
public LiveData getUser(int userId) {
// This isn't an optimal implementation. We'll fix it later.
final MutableLiveData data = new MutableLiveData<>();
webservice.getUser(userId).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
data.setValue(response.body());
}
// Error case is left out for brevity.
});
return data;
}
}
有没有办法,在第一次使用存储库模式调用时获取数据(没有脱机持久性)?