Fixed a crash when tracking was started from quick settings tile

This commit is contained in:
y20k 2020-01-29 13:37:04 +01:00
parent 907b238b0c
commit a48cd2d009
No known key found for this signature in database
GPG key ID: 824D4259F41FAFF6

View file

@ -19,6 +19,7 @@ package org.y20k.trackbook
import android.content.*
import android.graphics.drawable.Icon
import android.os.Build
import android.os.IBinder
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
@ -71,12 +72,26 @@ class TrackingToggleTileService(): TileService() {
trackerService.stopTracking()
}
else -> {
// start service via intent so that it keeps running after unbind
startTrackerService()
trackerService.startTracking(newTrack = false)
}
}
}
/* Start tracker service */
private fun startTrackerService() {
val intent = Intent(application, TrackerService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// ... start service in foreground to prevent it being killed on Oreo
application.startForegroundService(intent)
} else {
application.startService(intent)
}
}
/* Overrides onStopListening from TileService */
override fun onStopListening() {
super.onStopListening()