2

I'm pretty new to android can some one give me a better idea which one is a better way to save 2 edit texts on activity 1 and 24 edit texts on activity 2.

i need to save it with date / time stamp and be able to open by linking with onClick of a button.

what is the best option: shared preferences, sql db or file?

Please help me out here.

Mat Nadrofsky
  • 8,289
  • 8
  • 49
  • 73
codejunkie
  • 1,122
  • 3
  • 13
  • 29
  • I'm partial to using a database. In my first app I used a relative record file for something similar, but writing all the code to maintain an index, update, and delete the records was too much code writing. SharedPreferences will work, but you still have the housekeeping to write. SQLite does it all for you. – Howard Hodson Dec 22 '11 at 21:05
  • @howardHodson thx for the info is there any examples i can find on sql db lite as i'm very new to this concept. – codejunkie Dec 23 '11 at 10:16
  • To start, try http://www.vogella.de/articles/AndroidSQLite/article.html – Howard Hodson Dec 24 '11 at 18:51
  • @HowardHodson i have seen vogella tutorials not really clear enough they skim over some details expecting you to know the background knowledge i prefer to use android.com explanations and certainly stackoverflow answers :) – codejunkie Dec 28 '11 at 08:53

1 Answers1

1

Really it depends on what your application is going to do with that information and how you intend to use it.

Based on what you've briefly described, I'd recommend using an SQLite DB (with or without a Content Provider) to store the information just based on the fact that you're looking for a date/time stamp. Plus, it gives you a lot of flexibility going forward and it's not like there is a ton of overhead in that approach.

Shared Preferences are great too, but mainly are for key/value pairs and aren't nearly as flexible.

Last but not least, this question has some good info on using SQLite DB on Android and the differences in using a content provider vs. not.

Community
  • 1
  • 1
Mat Nadrofsky
  • 8,289
  • 8
  • 49
  • 73
  • Thx @MatNadrofsky Content provider hmm interesting again something new to me, quick question when i use SQLitDB method when i load the content back will it allow me to be set it in editText? and also can i link it with TextWatcher? – codejunkie Dec 23 '11 at 10:48
  • if you can use stringFromDB = cursor.getString(fieldOffset) to retrieve the text. then it's just a textView.setText(stringFromDB). – Howard Hodson Dec 27 '11 at 16:28