진행률 대화 상자에 문제가있어서 잘못된 작업을 찾을 수 없습니다. Localize 버튼을 누르면 코드가 새로운 AsyncTask를 수행하고 progressDialog가 시작되지만 마침내 코드 자체가 중지되고 오류가 표시됩니다. 나는 문제가 너무 길기 때문에 그것이라고 생각한다. 이 오류는 이것이다 : doInBackground을 실행하는 동안android AsyncTask error with ProgressDialog
오류가()
나는 문제가 publishProgress()로 생각하지만 어디에 어떻게 사용 몰라 발생했습니다. 여기
내 코드 :
public class GPSLocation extends AsyncTask<Void, Void, Void>
{
boolean running =true;
@Override
protected void onPreExecute()
{
super.onPreExecute();
pd = new ProgressDialog(Configuracion.this);
pd.setOnCancelListener(new DialogInterface.OnCancelListener(){
public void onCancel(DialogInterface dialog) {
pd.cancel();
}
});
longitude=0;
latitude =0;
getLonLat();
pd.setCancelable(true);
pd.setMessage("Getting GPS Location...");
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.show();
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
pd.setProgress(1);
// Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
}
@Override
protected void onPostExecute(Void result)
{
pd.dismiss();
}
@Override
protected Void doInBackground(Void... params) {
boolean isDataSubmitted = false;
while(!isDataSubmitted)
{
if(longitude !=0 && latitude!=0)
{
isDataSubmitted = true;
Log.d("LONGITUD", ""+longitude);
Log.d("LATITUDE", ""+latitude);
longitud.setText(String.valueOf(longitude));
latitud.setText(String.valueOf(latitude));
}
}
return null;
}
}
이 같이 GpsLocation 클래스의 부족, 그리고 Localize.setOnclicklistener (이)에서 호출; 여기
@Override
public void onClick(View v){
if (v.getId() == R.id.localiza){
new GPSLocation().execute();
}
}
이 방법
public void getLonLat(){
LocationManager milocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener milocListener = new MiLocationListener();
if (milocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
milocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,milocListener);
}else if (milocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
milocManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, milocListener);
}
}
감사합니다.
에 코드를 Chnage
에서의 setText 수 있습니다 "내 진행 대화 상자에 문제가있는"문제는 무엇인가? – SamonPostExecute()
죄송합니다 ... 깜빡 했으니 .. – croigsalvador
stacktrace를 게시 할 수 있습니까? – FoamyGuy