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)
|
Log.w(TAG, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unbindNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbindNow() {
|
||||||
|
if (bound) {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "Unbinding from: $serviceIntent")
|
Log.d(TAG, "Unbinding from: $serviceIntent")
|
||||||
context.unbindService(this)
|
context.unbindService(this)
|
||||||
|
|
|
@ -52,8 +52,14 @@ class GeocodeFuser(private val context: Context, private val lifecycle: Lifecycl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun destroy() {
|
private fun unbindNow() {
|
||||||
unbind()
|
for (backendHelper in backendHelpers) {
|
||||||
|
backendHelper.unbindNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun destroy() {
|
||||||
|
unbindNow()
|
||||||
backendHelpers.clear()
|
backendHelpers.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,7 @@ class GeocodeService : LifecycleService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
lifecycleScope.launch {
|
|
||||||
service.destroy()
|
service.destroy()
|
||||||
}
|
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
Log.d(TAG, "Destroyed")
|
Log.d(TAG, "Destroyed")
|
||||||
}
|
}
|
||||||
|
@ -187,7 +185,7 @@ class GeocodeServiceImpl(private val context: Context, private val lifecycle: Li
|
||||||
fuser.dump(writer)
|
fuser.dump(writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun destroy() {
|
fun destroy() {
|
||||||
fuser.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() {
|
fun bind() {
|
||||||
fusing = false
|
fusing = false
|
||||||
for (handler in backendHelpers) {
|
for (handler in backendHelpers) {
|
||||||
|
@ -64,8 +70,8 @@ class LocationFuser(private val context: Context, private val lifecycle: Lifecyc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun destroy() {
|
fun destroy() {
|
||||||
unbind()
|
unbindNow()
|
||||||
backendHelpers.clear()
|
backendHelpers.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,7 @@ class LocationService : LifecycleService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
lifecycleScope.launch {
|
|
||||||
service.destroy()
|
service.destroy()
|
||||||
}
|
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
Log.d(TAG, "Destroyed")
|
Log.d(TAG, "Destroyed")
|
||||||
}
|
}
|
||||||
|
@ -340,7 +338,7 @@ class LocationServiceImpl(private val context: Context, private val lifecycle: L
|
||||||
fuser.dump(writer)
|
fuser.dump(writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun destroy() {
|
fun destroy() {
|
||||||
fuser.destroy()
|
fuser.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue