Hey guys, I’m trying to migrate RxJava code dealin...
# android
Hey guys, I’m trying to migrate RxJava code dealing with SharedPreferences to Kotlin Flow. How correct migration should look like?
Copy code
private val keyChangesObservable: Observable<String>

  init {
    keyChangesObservable = io.reactivex.Observable.create(ObservableOnSubscribe<String> { emitter ->
      val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> emitter.onNext(key) }
      emitter.setCancellable { prefs.unregisterOnSharedPreferenceChangeListener(listener) }
Please check callbackFlow function documentation, it shows how to write Flow wrapper for callback API
Tho, there is no way to share it yet, but not a big deal for this case imo
Also, please avoid cross-posting: https://kotlinlang.slack.com/archives/C1CFAFJSK/p1565910781264800 …and consider sending only one message for the same question to avoid ambiguity when starting a thread.
Probably more broad you can check https://commonsware.com/presos/androidSummit2019