diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_operations/FileOperationService.kt b/app/src/main/java/sushi/hardcore/droidfs/file_operations/FileOperationService.kt index 4cc66d2..c446f3d 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_operations/FileOperationService.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_operations/FileOperationService.kt @@ -104,7 +104,9 @@ class FileOperationService : Service() { activity.lifecycle.addObserver(object : DefaultLifecycleObserver { override fun onDestroy(owner: LifecycleOwner) { 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( diff --git a/app/src/main/java/sushi/hardcore/droidfs/util/AndroidUtils.kt b/app/src/main/java/sushi/hardcore/droidfs/util/AndroidUtils.kt index 7bd6509..b92e21f 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/util/AndroidUtils.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/util/AndroidUtils.kt @@ -28,7 +28,7 @@ object AndroidUtils { /** * A [Manifest.permission.POST_NOTIFICATIONS] permission helper. * - * Must be initialized before [Activity.onCreate]. + * Must be initialized before [Activity.onCreate] finishes. */ class NotificationPermissionHelper(val activity: A) { private var listener: ((Boolean) -> Unit)? = null