0
我想使用异步任务来渲染和添加标记到谷歌地图,但地图永不停止加载。我正确使用doInBackground和onPostExecute方法吗?我不确定如何解决这个问题。AsyncTask不会终止
这里是我的两个异步任务类
public class addMarkers extends AsyncTask<Void, String, GoogleMap> {
String result;
ProgressDialog pdia;
protected void onPostExecute(Result result) {
pdia.dismiss();
}
@Override
protected GoogleMap doInBackground(Void... params) {
publishProgress("Loading..."); // Calls onProgressUpdate()
MapsFragment.HOME = new LatLng(30.284273, -97.744777);
mGoogleMap.addMarker(new MarkerOptions().position(HOME));
return mGoogleMap;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pdia = ProgressDialog.show(getContext(), "Please wait", "Loading data from database.", true, false);
}
@Override
protected void onProgressUpdate(String... text) {
}
}
public class renderMap extends AsyncTask<Void, String, View>{
ProgressDialog pdia;
LayoutInflater inflater;
ViewGroup container;
renderMap(LayoutInflater inflater, ViewGroup container){
this.inflater = inflater;
this.container = container;
}
protected void onPostExecute(String result) {
pdia.dismiss();
}
@Override
protected View doInBackground(Void... params) {
publishProgress("Loading..."); // Calls onProgressUpdate()
mView = inflater.inflate(R.layout.fragment_maps, container, false);
return mView;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pdia = ProgressDialog.show(getContext(), "Please wait", "Loading data from database.", true, false);
}
@Override
protected void onProgressUpdate(String... text) {
}
}