简体   繁体   中英

Custom DialogPreference in Android

In My Project I am using SeekBarPreference . I take reference from http://android.hlidskialf.com/blog/code/android-seekbar-preference code work perfect without any error but when i fetch share Preference value in other activity. then i always found 0 why? I use below code for get share Preference value:-

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
 String str=Integer.toString( prefs.getInt("duration", 0));

Using Shared preferences code for get and put the values below:

code for put the values into sharedpreferences:

public static final String PREFS_NAME = "Prefs";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);
SharedPreferences.Editor editor = settings.edit();  
editor.putInt("no", 11);
editor.commit();

Code for get the values from sharedpreferences:

  SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);   

    String in=Integer.toString(settings.getInt("no", 0));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM