SharedPreferences.onSharedPreferenceChangeListener not being called consistently

前端 未结 8 1180
终归单人心
终归单人心 2020-11-22 06:47

I\'m registering a preference change listener like this (in the onCreate() of my main activity):

SharedPreferences prefs = PreferenceManager.get         


        
8条回答
  •  甜味超标
    2020-11-22 07:28

    So, I don't know if this would really help anyone though, it solved my issue. Even though I had implemented the OnSharedPreferenceChangeListener as stated by the accepted answer. Still, I had an inconsistency with the listener being called.

    I came here to understand that the Android just sends it for garbage collection after some time. So, I looked over at my code. To my shame, I had not declared the listener GLOBALLY but instead inside the onCreateView. And that was because I listened to the Android Studio telling me to convert the listener to a local variable.

提交回复
热议问题