Hi all I am using shared preferences in my application. I am using action bar. In this action i am having customized spinner. I have store the value into the shared preference while onNavigationItemSelected in my main activity. Which means tab zero. Lie this.
main_prefs = getSharedPreferences("final_city_id", MODE_PRIVATE);
// detail is sharedpreference name
SharedPreferences.Editor editor = main_prefs.edit();
// to remove paricular value from detail
String spusername = main_prefs.getString("changed_city_id", "novalue");
if(spusername!= null && !spusername.equals(""))
{
System.out.println("inside if condition........");
Log.e("Spusername != null","-->"+spusername);
editor.remove("changed_city_id");
Log.e("value removed","-->"+spusername);
editor.putString("changed_city_id",spinner_city_id);
editor.commit();
String spusername1 = main_prefs.getString("changed_city_id", "novalue");
System.out.println("spusername1```````````"+spusername1);
}
else
{
System.out.println("inside else condition........");
editor.putString("changed_city_id",spinner_city_id);
editor.commit();
String spusername2 = main_prefs.getString("changed_city_id", "novalue");
System.out.println("spusername2```````````"+spusername2);
}
Now i move on to tab 2 or 3 and then again selecting spinner. My values has to be change. And my shared preference value is also change. Now I want to check if the shared preference is changed or not in my 2 tab and my third tab. Which means another activity. But my spinner's onNavigationItemSelected methos is in my zero tab. So i am using OnSharedPreferenceChangeListener. In some link suggest this one. Because when shared preference is change this override method is automatically triggered. I searched lot of things and tired it. but i can't able get in clear way. Can anybody clear me? Thanks in advance.