Skip to main content

Posts

Showing posts from August, 2013

Shared Preferences Tutorial

SharedPreferences are used to store some data persistently. Similar to database in functionality, but easy to use as compare to database and developer prefer SharedPreferences for storing small amount of data Usually use to store the flag variable values. Like Storing sound on /off flag of application We can get SharedPreferences object using following method.   Public abstract SharedPreferences getSharedPreferences (String name, int mode) name Desired Name of the file. If a preferences file by this name does not exist, it will be created when you retrieve an editor (SharedPreferences.edit ()) and then commit changes (Editor. Commit ()). mode File Creation Mode. Use 0 or MODE_PRIVATE for the default operation. SharedPreferences mSharedPreferences =getApplicationContext().getSharedPreferences( "pref" , MODE_PRIVATE );         /*          * TO WRITE VALUES INTO THE   PREFERENCE FILE          */