在 android 应用程序中使用 asynctask runner 时,我在每 5 秒后在 while 循环中运行 asynctaskrunner 以在文本视图中显示 gps 坐标时感到有些震惊。
包 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;
}
}