안드로이드 응용 프로그램에서 asynctask runner를 사용하는 동안, 텍스트보기에서 gps 좌표를 표시하기 위해 매 5 초마다 while 루프에서 asynctaskrunner를 실행하는 중 일부가 발생했습니다.asynctaskrunner 안드로이드 응용 프로그램에서 오류가 발생했습니다.
package com.example.gpsproject;
import android.content.Context;
import android.location.Location;
import android.os.AsyncTask;
import android.widget.TextView;
public class AsyncTaskRunner extends AsyncTask<Void,Void,Void> {
private final Context mContext;
TextView latitude,longitude;
public AsyncTaskRunner(Context c,TextView lat,TextView lon) {
// TODO Auto-generated constructor stub
mContext = c;
latitude = lat;
longitude = lon;
}
Location a = new Location("zfcdha");
String lonii,latii;
private void sleep(int i) {
// TODO Auto-generated method stub
}
protected void onPostExecute() {
}
@Override
protected void onPreExecute() {
}
protected Void doInBackground(Void... params) {
try {
GPSTracker mytracker = new GPSTracker(mContext);
while(true){
latii = "" + a.getLatitude();
lonii = "" + a.getLongitude();
latitude.setText(latii);
longitude.setText(lonii);
sleep(5000);
}
} catch (Exception e) {
e.printStackTrace();
;
}
;
return null;
}
}
백그라운드 스레드에서'setText()'를 호출하고 있습니다. 그러지 마. – Geros