wood burning stoves*
The moose likes Android and the fly likes why there is need for shared preference. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "why there is need for shared preference." Watch "why there is need for shared preference." New topic
Author

why there is need for shared preference.

Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
Hi All,

I am new to Android Platform. I have just started coding in Android.

In the concept of Data storage every book talks about Shared Prefereces.

My understanding od shared preference is that Its used for storing primitive key value pairs in the file. But What I don't understand is we can accomplish this even using a

bundle in Intent. WHy do we need a seperate concept of shared preferences.

Please correct me if my concepts are wrong.


Thanks and Regards,
Anil Deshpande


Anil Deshpande
SCJP 1.5, SCWCD 1.5
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Preferences are meant for storing user preferences and application status that needs to be persistent between app invocations. Sure you can write code that does the same, but why do so if Android has something built-in that works?


Ping & DNS - updated with new look and Ping home screen widget
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
Ok, Can you cite an example for make the concept more apparant. If the preferences are being used for storing preferences, can't we do it in SQlite. Why preferecnes?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Anil Deshpande wrote:If the preferences are being used for storing preferences, can't we do it in SQlite. Why preferecnes?


Ulf Dittmer wrote:Sure you can write code that does the same, but why do so if Android has something built-in that works?


Also, defining the preferences in the xml/preferences.xml file (instead of coding them up yourself) provides you with a nice preferences screen for very little work - very handy.

See http://www.androidguys.com/2008/09/29/whats-your-preference-part-one/, http://www.androidguys.com/2008/10/07/whats-your-preference-part-two/ and http://www.ibm.com/developerworks/xml/library/x-androidstorage/index.html for more information.
 
 
subject: why there is need for shared preference.
 
Similar Threads
is their need of new platform and what dou you think next ?
Android Begginer
How did you start or know about Android?
SharedPreference not working
how to store and retrieve array list value in shared preference in android