Make sure we unbind services instantly when required to not leak service
This commit is contained in:
parent
daa8c33eae
commit
0b41056020
|
@ -54,6 +54,12 @@ abstract class AbstractBackendHelper(private val TAG: String, private val contex
|
|||
Log.w(TAG, e)
|
||||
}
|
||||
}
|
||||
unbindNow()
|
||||
}
|
||||
}
|
||||
|
||||
fun unbindNow() {
|
||||
if (bound) {
|
||||
try {
|
||||
Log.d(TAG, "Unbinding from: $serviceIntent")
|
||||
context.unbindService(this)
|
||||
|
|
|
@ -52,8 +52,14 @@ class GeocodeFuser(private val context: Context, private val lifecycle: Lifecycl
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun destroy() {
|
||||
unbind()
|
||||
private fun unbindNow() {
|
||||
for (backendHelper in backendHelpers) {
|
||||
backendHelper.unbindNow()
|
||||
}
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
unbindNow()
|
||||
backendHelpers.clear()
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,7 @@ class GeocodeService : LifecycleService() {
|
|||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
lifecycleScope.launch {
|
||||
service.destroy()
|
||||
}
|
||||
service.destroy()
|
||||
super.onDestroy()
|
||||
Log.d(TAG, "Destroyed")
|
||||
}
|
||||
|
@ -187,7 +185,7 @@ class GeocodeServiceImpl(private val context: Context, private val lifecycle: Li
|
|||
fuser.dump(writer)
|
||||
}
|
||||
|
||||
suspend fun destroy() {
|
||||
fun destroy() {
|
||||
fuser.destroy()
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,12 @@ class LocationFuser(private val context: Context, private val lifecycle: Lifecyc
|
|||
}
|
||||
}
|
||||
|
||||
private fun unbindNow() {
|
||||
for (handler in backendHelpers) {
|
||||
handler.unbindNow()
|
||||
}
|
||||
}
|
||||
|
||||
fun bind() {
|
||||
fusing = false
|
||||
for (handler in backendHelpers) {
|
||||
|
@ -64,8 +70,8 @@ class LocationFuser(private val context: Context, private val lifecycle: Lifecyc
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun destroy() {
|
||||
unbind()
|
||||
fun destroy() {
|
||||
unbindNow()
|
||||
backendHelpers.clear()
|
||||
}
|
||||
|
||||
|
|
|
@ -46,9 +46,7 @@ class LocationService : LifecycleService() {
|
|||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
lifecycleScope.launch {
|
||||
service.destroy()
|
||||
}
|
||||
service.destroy()
|
||||
super.onDestroy()
|
||||
Log.d(TAG, "Destroyed")
|
||||
}
|
||||
|
@ -340,7 +338,7 @@ class LocationServiceImpl(private val context: Context, private val lifecycle: L
|
|||
fuser.dump(writer)
|
||||
}
|
||||
|
||||
suspend fun destroy() {
|
||||
fun destroy() {
|
||||
fuser.destroy()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue