0

In my application i am using Preference to get the data.

My code is:

SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
        sp.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {

            @Override
            public void onSharedPreferenceChanged(SharedPreferences arg0, String arg1) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplication(), "Settings changed", Toast.LENGTH_LONG).show();
            }
        });

But the Toast is not Showing when the data is changed in Preference. I am using EditText to get data.

Thanks...!

Hari krishnan
  • 2,060
  • 4
  • 18
  • 27
  • Show the code where you change the data. Maybe you forgot `commit()` or `apply()`? – stealthjong Sep 02 '14 at 07:56
  • @stealthjong i am not changing in preference. I want to get the data when changed in the Preference Settings Activity . In the XML there are EditTextPrefernce boxes. I want to manipulate this. – Hari krishnan Sep 02 '14 at 08:00
  • Please see this post, http://stackoverflow.com/questions/2542938/sharedpreferences-onsharedpreferencechangelistener-not-being-called-consistently/3104265#3104265. In Short: When you use the listener as an anonymous inner class it gets a target of the garbage collection as soon as it leaves the current scrope – reVerse Sep 02 '14 at 09:02

0 Answers0