相关疑难解决方法(0)

如何使IntentService的线程保持活动状态?

我正在编写一个跟踪用户位置的测试应用程序.我的想法是,我可以启动一项服务,然后注册位置更新.现在我正在使用IntentService.

服务代码(不起作用......)看起来像这样:

public class GpsGatheringService extends IntentService {

// vars
private static final String TAG = "GpsGatheringService";
private boolean stopThread;

// constructors
public GpsGatheringService() {
    super("GpsGatheringServiceThread");
    stopThread = false;
}

// methods
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand()");
    return super.onStartCommand(intent, flags, startId);
}

@Override
protected void onHandleIntent(Intent arg0) {
    // this is running in a dedicated thread
    Log.d(TAG, "onHandleIntent()");
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    LocationListener locationListener = new LocationListener() {

        @Override
        public void onStatusChanged(String …
Run Code Online (Sandbox Code Playgroud)

multithreading android intentservice

5
推荐指数
1
解决办法
7643
查看次数

标签 统计

android ×1

intentservice ×1

multithreading ×1