샘플 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