FileOperationService: remove the correct notification helper on activity destroy
This commit is contained in:
parent
2d5f5a82c9
commit
07f5f8b5d9
@ -104,7 +104,9 @@ class FileOperationService : Service() {
|
|||||||
activity.lifecycle.addObserver(object : DefaultLifecycleObserver {
|
activity.lifecycle.addObserver(object : DefaultLifecycleObserver {
|
||||||
override fun onDestroy(owner: LifecycleOwner) {
|
override fun onDestroy(owner: LifecycleOwner) {
|
||||||
activity.unbindService(serviceConnection)
|
activity.unbindService(serviceConnection)
|
||||||
service.notificationPermissionHelpers.removeLast()
|
// Could have been more efficient with a LinkedHashMap but the JDK implementation doesn't allow
|
||||||
|
// to access the latest element in O(1) unless using reflection
|
||||||
|
service.notificationPermissionHelpers.removeAll { it.activity == activity }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
activity.bindService(
|
activity.bindService(
|
||||||
|
@ -28,7 +28,7 @@ object AndroidUtils {
|
|||||||
/**
|
/**
|
||||||
* A [Manifest.permission.POST_NOTIFICATIONS] permission helper.
|
* A [Manifest.permission.POST_NOTIFICATIONS] permission helper.
|
||||||
*
|
*
|
||||||
* Must be initialized before [Activity.onCreate].
|
* Must be initialized before [Activity.onCreate] finishes.
|
||||||
*/
|
*/
|
||||||
class NotificationPermissionHelper<out A: AppCompatActivity>(val activity: A) {
|
class NotificationPermissionHelper<out A: AppCompatActivity>(val activity: A) {
|
||||||
private var listener: ((Boolean) -> Unit)? = null
|
private var listener: ((Boolean) -> Unit)? = null
|
||||||
|
Loading…
Reference in New Issue
Block a user