Skip to content

Android Shared Preferences class in Java language + Single UI using some of its methods + picture of it's actual path

Notifications You must be signed in to change notification settings

mossssama/AndroidSharedPreferencesModule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

AndroidSharedPreferencesModule

Android Shared Preferences class in Java language + Single UI using some of its methods + picture of it's actual path

Usage


[1] Put SharedPrefs class in your app folder


[2] Use the following in the place you want to use SharedPrefs; substitute the i/p parameters by their equivalent in your project

// Making an instance of the module
SharedPrefs.init(getContenxt())

/* Used them incase you want to track changes in SharedPrefs */
// MyPrefsListener myPrefsListener = new MyPrefsListener();
// SharedPrefs.getSharedPreferences().registerOnSharedPreferenceChangeListener(myPrefsListener);
/* *************************************************** */
    
// Writing in sharedPrefs
SharedPrefs.write(key,value);


// Reading from sharedPrefs
SharedPrefs.readMap(key,value);

// Deleting from sharedPrefs
SharedPrefs.remove(key);

[3] Add the following inner class in any Activity/Fragment you want to track a SharedPrefs' key changes in it

private class MyPrefsListener implements SharedPreferences.OnSharedPreferenceChangeListener {

        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            if (key.equals(keyYouWantToTrackItsChanges)) {
                if(SharedPrefs.readMap(key, defaultValue))  { /* Do specific Operation */ } 
                else                                        { /* Do Another Operation */ }   
            }
        }
    }

[4] Check this example on Tracking changes In SharedPrefs class


To Track the actual place of the sharedPrefs xml file

Screenshot (760) Screenshot (761)

About

Android Shared Preferences class in Java language + Single UI using some of its methods + picture of it's actual path

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages