public Observable < String > observePreferences ( ) { return Observable . create ( new ObservableOnSubscribe < String > ( ) { @ Override public void subscribe ( final @ io . reactivex . annotations . NonNull ObservableEmitter < String > e ) { preferences . registerOnSharedPreferenceChangeListener ( new SharedPreferences . OnSharedPreferenceChangeListener ( ) { @ Override public void onSharedPreferenceChanged ( SharedPreferences sharedPrefs , String key ) { if ( ! e . isDisposed ( ) ) { e . onNext ( key ) ; } } } ) ; } } ) ; }
returns RxJava Observable from SharedPreferences used inside Prefser object . You can subscribe this Observable and every time when SharedPreferences will change subscriber will be notified about that and you will be able to read key of the value which has been changed .