The service runs in the background all the time, but for some reason my function saveUserLocation();
, stop after some time. When the app is open it runs the whole time. Here is some pictures to show the service still runs in the background after I close the app, and the other picture I close the app and then the logD
still prints for some seconds, then it stops.
service in background
LogD -> logcat suddenly just stops
Code from service
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand: called");
notificationGenerator();
getLocation();
return START_NOT_STICKY;
}
private void getLocation() {
// ---------------------------------- LocationRequest ------------------------------------
// Create the location request to start receiving updates
LocationRequest mLocationRequestHighAccuracy = new LocationRequest();
mLocationRequestHighAccuracy.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequestHighAccuracy.setInterval(UPDATE_INTERVAL);
mLocationRequestHighAccuracy.setFastestInterval(FASTEST_INTERVAL);
mFusedLocationClient.requestLocationUpdates(mLocationRequestHighAccuracy, new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
Log.d(TAG, "(*) Service Running");
}
},
Looper.myLooper()); // Looper.myLooper tells this to repeat forever until thread is destroyed
}
Manifest
<service android:name=".service.Service"
android:enabled="true"
android:exported="true"/>
It dosen't say any error in Logcat, it just stops, and when I start the app again it continues. Any ideas why it stops?