I'm struggling with a design issue. I have a UI that asks users for data input like event dates and times. Once collected on the UI, should I save the data to a SQLite database and then push the data from the database to cards on a list using RecyclerView and CardView? Or should it be the other way around: save the data input to a RecyclerView list using cards and then push the data to the SQLite database? Please note: the cards in the RecyclerView will be editable, meaning the user entered date can be updated or deleted and then the database entry would have to be updated or deleted. Any thoughts here?
3 Answers
I would suggest having a good look at using sharedPreferences. They may sound/look like a pain but they are quite useful for doing what it sounds like you need. If I am completely mistaken ignore this, else here are a couple of links outlining sharedPreferences How to use SharedPreferences in Android to store, fetch and edit values and the good old android docs http://developer.android.com/reference/android/content/SharedPreferences.html
-
Hi, thanks for your note. Are you recommending SharedPreferences because they are easier to manage than an SQLite database? – AJW Dec 22 '15 at 02:28
-
I would say sqlite is probably easier to manage in general, but SharedPreferences gives you a good way to hold data in the app as required and then send it to the database when you want/need to do so. – Theyna Dec 22 '15 at 02:33
-
Ok I'll take a look at that. But what is the advantage of sending the data to SharedPreferences for storage first, before sending to the database? – AJW Dec 22 '15 at 02:36
-
I'm not sure how you are managing you app, but it could save you using a RecyclerView or a CardView, also holding data in SharedPreferences allows you to do fewer transactions, though they may be larger, which could help your app to run smoother. It also allows editing of the data without multiple commits or selects from the database. Fewer transactions makes the security of the database easier to manage also. – Theyna Dec 22 '15 at 02:41
-
The data collected from the user input will be shown on a card and the cards all shown using a RecyclerView. I will look for a webpage that shows an example...give me a minute to find the link. Here is the link that shows an example of showing data in a card and RecyclerView list: https://www.binpress.com/tutorial/android-l-recyclerview-and-cardview-tutorial/156 – AJW Dec 22 '15 at 02:47
-
The RecyclerView list and cards are down at the bottom of the webpage. – AJW Dec 22 '15 at 02:53
-
Ok, I see what you are trying to do now, I would say your best option is to keep doing what you are and push data from the cards to your database. – Theyna Dec 22 '15 at 02:53
-
Ok, would I even need the database to save/persist the data when the user closes the app? Or can I just push the data to the cards and be done? Meaning a card will always be in the RecyclerView list unless the user deletes a card. – AJW Dec 22 '15 at 02:57
-
the cards should hold the data, though don't take my word for it as I've never tried them, but the database would ultimately be more useful if you wanted to access the same data in the app on multiple devices. – Theyna Dec 22 '15 at 09:01
you may create a list and read datas from database to your list,and when you change your data,both change list and database.and the adapter will only based on datas in your list,but not based on datas in database,because read or write data from database will cost you alot of time!

- 57
- 5
-
So is there any advantage to having the database? Or should I just push the data from the UI to the CardView cards and create a RecyclerView list from the cards? – AJW Dec 22 '15 at 02:39
-
I think just push it will be fine,or you can create a cache class to save your datas,so you don't need to push datas,just read or change the cache class – chichiangho Dec 22 '15 at 02:48
Actually I dont see your problem here. You have to save your collected data anyway, right? Then saving data to your database for safe action. After that, you can push data to your recyclerView
without any performace problem with notifyDataSetChanged()

- 8,052
- 9
- 46
- 86
-
Can I just push the data to the RecyclerView and the data will persist/save when the user closes the app and not use a database? – AJW Dec 22 '15 at 03:40
-
actually no. You have to save it to db or using sharedpreference. If there's not much data, sharedPreference is an option. Otherwise, you should use database. There's a lot of `DatabaseHelper` library which help you easy to manage your db with only 5 mins of trying as GreenDao: http://greendao-orm.com/ – Kingfisher Phuoc Dec 22 '15 at 03:45
-
Ok so use greenDAO to get up and running fast rather than learning lots of SQLite code? Are there any limitations to using ORMs? – AJW Dec 22 '15 at 03:51