私はサンプルAndroidアプリを開発しています。私はMVPパターンに従い、プレゼンタークラスを実装しようとしています。私のプレゼンターの実装では、私がプレゼンタークラスを実装するためのベストプラクティスを探していますし、私は別々のクラスにAsyncTask
を移動し、より良いアプローチとなり、より汎用的な方法でそれを実装すると信じてAndroid MVP:ベストプラクティス
public class WeatherForecastPresenter extends AsyncTask<Void, Void, WeatherForecast> {
private double latitude;
private double longitude;
private String address;
// class that makes sync OkHttp call
private WeatherForecastService weatherForecastService;
// interface that has callback methods
private WeatherForecastView weatherForecastView;
public WeatherForecastPresenter(WeatherForecastView weatherForecastView, double latitude, double longitude, String address) {
this.latitude = latitude;
this.longitude = longitude;
this.address = address;
this.weatherForecastView = weatherForecastView;
weatherForecastService = new WeatherForecastService();
}
@Override
protected void onPreExecute() {
weatherForecastView.toggleRefresh();
}
@Override
protected WeatherForecast doInBackground(Void... voids) {
// gets weather forecast data of given location
return weatherForecastService.getCurrentWeather(latitude, longitude);
}
@Override
protected void onPostExecute(WeatherForecast weatherForecast) {
weatherForecastView.toggleRefresh();
if (weatherForecast != null) {
weatherForecastView.updateUi(weatherForecast, address);
} else {
weatherForecastView.displayErrorDialog();
}
}
}
を下回っているが、私はできませんでした適切な解決策を見つける。 あなたが私を助けることができれば幸いです。
私はretrofit、rx、またはottoのようなものを使用したくありません。 – Tartar