0

I have an android app that displays a list of items in a Custom ListView using checkboxes.I need to write a code that stores the checked and unchecked items locally on my phone or emulator(since now presently working on localhost). Is there any way to store the data locally on the phone. I have heard of SQLLite and SharedPreferences but I have an application made already and for me it would better using the same for storing the data rather than creating a separate code structure as in the case of SQLLite.

Also the data I am going to store, I plan to use it to send to a remote database via web services. So considering all this ,

Can anyone tell me how to go about using SharedPreferences for my application?

Here's my present android code : http://pastebin.com/VvVU5Lrb

0

4 Answers 4

2

I would convert the list to JSON string and save it in shared preferences, both operations are simple and the JSON format will allow a simple transfer and parsing of the data in the server side as well.

1
  • Hey thanks !! I suggest please just have a look at my code ..I have given a link in my question..just tell me what changes should I make to convert my list into JSON..my String arr2[]; contains the list Aug 22, 2011 at 12:46
2

Here's a link for you

Using Shared Preferences

This should help.

1
  • check this Android code of mine : pastebin.com/VvVU5Lrb ... see line no 67 ..can u tell me where should I put the sharedpreferences code as per my app ? Aug 22, 2011 at 12:40
1

Check this once. Here you will find the way how to use shared preferences and writing and reading values using shared preferences.

http://androidcodesnips.blogspot.com/2011/06/shared-preferences-persistent-storage.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Androidcodes+%28AndroidCodes%29

4
  • I will be storing the data temporarily..Once my job is done I would be calling a web service to take the data that is stored locally using SharedPreferences and transfer it to a remote database..so u think it SharedPreferences will be useful for me then ? Aug 22, 2011 at 13:01
  • for the temporarily saving data use normal variables. Shared preferences stores the data until we uninstall the application.
    – harish
    Aug 22, 2011 at 13:06
  • arrays would also do right? Shared Preferences will store the data until application is uninstalled but my question is that can I transfer the data do the remote server via my service..Also my data is large and I don't plan to store a single item once the transfer has taken place via the web service Aug 22, 2011 at 13:13
  • Shared prefs also removed if user deletes app data, which they may do if want to free space on device.
    – ComeIn
    Jun 24, 2016 at 5:05
0

SharedPreferences is like creating session. It is good with small data such as username, email, password, etc. If you need to temporary store large data, I suggest sqlite instead. After the data has been manipulated, you can store in your mysql, or others by httprequest/response and php. (Maybe using List<NameValuePair> params = new ArrayList<NameValuePair>(); . . .)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.