Как запустить класс с расширением IntentService, когда onLocationChanged

Это мой код IntentService. Этот класс называется (inBackground):

package com.example.seadog.gps;

import android.app.IntentService;
import android.content.Intent;

import org.json.JSONObject;

public class inBackground extends IntentService {

    public inBackground() {
        super("GPSLocation");
    }

    @Override
    protected void onHandleIntent(Intent intent) {

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        JSONObject json = GlobalConfig.Json;
        new MyAsyncTask().execute(json);

        return super.onStartCommand(intent, flags, startId);
    }

}

Когда я пытаюсь запустить этот класс, когда мое местоположение изменяется таким образом:

Intent intent = new Intent(this, inBackground.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, 3000, pendingIntent);

тогда мое приложение сразу закрывается. Конечно, приведенный выше код я выполняю в onLocationChanged. Что случилось?

0 ответов

Другие вопросы по тегам