onLocationChanged时run class如何扩展IntentService

时间:2015-11-23 14:03:29

标签: java android alarmmanager android-intentservice

这是我的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 个答案:

没有答案