关闭应用程序时,AlarmManager不会执行

时间:2016-05-31 07:27:53

标签: android service broadcastreceiver alarmmanager

我将此项目用于我的应用程序:https://github.com/nickfox/GpsTracker

当我在4.4中运行它时,一切正常,当我关闭应用程序时,gps跟踪器仍在运行。但在5.0中,它不是。当任务管理器关闭时,警报管理器和服务与应用程序关闭。

它有什么问题?请帮我解决一下

当我关闭应用程序时,似乎电源管理是紧密的服务。我可以在api 21 ???

中将应用添加到白名单

1 个答案:

答案 0 :(得分:0)

您可能需要查看LocationService课程。

onStartCommand Service返回START_NOT_STICKY,这意味着如果它被杀死,操作系统将不会重新启动此Service

LocationService中尝试以下内容:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // if we are currently trying to get a location and the alarm manager has called this again,
    // no need to start processing a new location.
    if (!currentlyProcessingLocation) {
        currentlyProcessingLocation = true;
        startTracking();
    }

    return START_STICKY;
}