[英]How to excute AsyncTask inside onLocationChanged() method in Android
I have class that extends AsyncTask
class and I create instance of this class of this AsyncTask
class uses data comes from GPS driver from the method 我有扩展AsyncTask
类的类,并创建了该AsyncTask
类的此类的实例,该类使用数据来自方法中的GPS驱动程序
public void onLocationChanged(Location location) {}
from interface LocationListener
. 从LocationListener
接口。
I want to know why why the application to execute AsyncTask
instance inside the method onLocationChanged()
?! 我想知道为什么应用程序为什么要在onLocationChanged()
方法内部执行AsyncTask
实例? As I want to execute something in background only when the location is changed 因为我只想在位置更改时在后台执行某些操作
public void onLocationChanged(Location location) {
new yourAsyncTaksk(location).execute();
}
make a constructor for your asyncTask , with Location object as argument. 使用Location对象作为参数为asyncTask构造一个构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.