Skip to content

Instantly share code, notes, and snippets.

@eugenebrusov
Created October 26, 2018 09:22
Show Gist options
  • Save eugenebrusov/8ec243835474685934c3916ece7ab7f1 to your computer and use it in GitHub Desktop.
Save eugenebrusov/8ec243835474685934c3916ece7ab7f1 to your computer and use it in GitHub Desktop.
Exception on broadcast unregister
Flowable
.create<Boolean>({ emitter ->
val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
try {
throw RuntimeException("Test exception")
} catch(e: Throwable) {
emitter.tryOnError(e)
}
}
}
try {
application.registerReceiver(broadcastReceiver, IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION))
emitter.setCancellable {
throw RuntimeException("unregisterReceiver exception")
application.unregisterReceiver(broadcastReceiver)
}
} catch (e: Throwable) {
emitter.tryOnError(e)
}
}, BackpressureStrategy.MISSING)
.onErrorReturn { false }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment