我已经创建了一个服务来定期获取设备的当前位置.即使从最近打开的应用程序中清除了应用程序,我也希望该服务在后台运行.目前,该服务仅在后台运行,直到应用程序出现在最近打开的应用程序中,但在应用程序被刷掉(或以其他方式杀死)时立即停止.我已经尝试过堆栈溢出中的各种帮助,但我无法解决这个问题.请帮忙.这是我的服务代码.
package com.packr.services;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.location.Location;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import java.text.DateFormat;
import java.util.Date;
/**
* Created by Arindam on 11-Dec-15.
*/
public class LocationService extends Service implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
protected static final String TAG = "packrMATE";
/**
* The desired interval for location updates. Inexact. Updates may be …Run Code Online (Sandbox Code Playgroud) android restart background-service android-service android-service-binding