androidandroid-toastpreferencescreenandroid-sharedpreferencescheckboxpreference

Why Toast appears more times than I need?


The problem is that a Toast appears as many times as you open Settings activity, while I need it only once after each click on CheckBox.

Thanks in advance to everyone, who tried to improve my code.

More detailed description of how the code works:


Solution

  • You should call settings.unregisterOnSharedPreferenceChangeListener() in your onPause() method when you leave the Activity. And I suggest to call settings.registerOnSharedPreferenceChangeListener() in your onResume() callback rather than onCreate().