I am developing one small application where i am adding items one by one in the recyclerview if the user click on the '+' symbol in the menu bar.
The problem is i want to save the data(items) permanently in recyclerview even we close the app.So that the user can come again and edit the item which are in recyclerview.
Kindly let me know how can i achieve this since i am new to this..Thanks for your help!!!
Here is the lots of option available to store data in locally or live,
One is store in Preference help of json or normaly,
Second way is store inside of local Database like SQLLite or also Realme is available,
Third way is store it online help of server or directly using firebase,
Another way is store it in file, and read and write and edit,
I am suggesting if your data size is small then store with Preference and data size is big then take data base and if you dont want to store locally then you can take help of firebase or web service.
to do this you have several options :
1- save in SharedPreferences
2- use DataBase : sqliteDatabase or Realm
3- write in File
Related
As you see on app like facebook, twitter, etc you have list of content in home page. if you close the app then open it again, you still have those content without load again from server.
currently i use this code to save all value in my app
SPref.setPref(getActivity(), Config.USER_ID, lb.userId);
SPref.setPref(getActivity(), Config.USER_NAME, lb.name);
SPref.setPref(getActivity(), Config.USER_EMAIL, lb.email);
its just save a string or a an int value not a list. i used saving data at local device with sqlite and a file for my other project. in this case in my new project, i want to make sure which way is better for saving list value.
by the way, i use SharedPreferences because someone told me its faster.
shared preference
is only to store KEY , VALUE pair, So you can store here small amount of data like username , some flags etc.
To store your normal contents like here you want to store list.
Use SQLite for this is the list will not frequently going to changed, or it will going to modify then use Cache.
Please follow this links for better understanding
https://developer.android.com/guide/topics/data/data-storage.html
https://developer.android.com/reference/android/util/LruCache.html
Shared Preferences certainly are very fast, but those aren't meant to be stored with a huge data set, As the name suggest those are meant to store the preference data of the app in a key value pair for example
setting the sound on/off
setting the logged in status
setting the day/night theme for the app.
In the above example whenever user changes a setting you can just store it in SP, and use it next time to make any decisions
For Larger data set, you have to use SQL lite
https://developer.android.com/training/basics/data-storage/databases.html
Or Realm DB(Third party library)
https://realm.io/
This question already has answers here:
How to store data from my app
(5 answers)
Closed 7 years ago.
I want to create an application in which the user have two edittexts. Whenever the user types in the edittexts, I want to store it and retrieve when the user wants it. Also the user should be able to store as many files which contains his data as possible. How to do that in android?
Just get the text from your EditText:
yourEditText.getText().toString()
Then use SharedPreferences to save and retrieve the data as needed
There are a few options you have when it comes to storing data in Android.
The most simple way would be storing values in SharedPreferences, but I wouldn't advise trying this because
the user should be able to store as many files which contains his data as possible
So, you've got a couple other options
1. Saving Files
You could save one or more files to the users phone, and read it back in when the user wants to retrieve it.
2. Saving Data in SQL Databases
You could use a SQLite Database to manage the data in a more structured way.
Saving data to a database is ideal for repeating or structured data, such as contact information.
In your case, it really depends on what you are planning to do with this app. If you feel that you may expand the information the user can save, I would say go with a database. If you are sure that you will only need the info from the two EditTexts I think writing to files would suffice.
Depending on your use case you have basically three choices in Android to store data:
Shared preferences
Create a file in the file system
Use a database
Further information about each option can be found here: http://developer.android.com/training/basics/data-storage/index.html
I wanted to know how to create something like this to save information, after a form has been filled out? This is from the App Timetable and I couldnt get any information on how to do this? Any Suggestions/Solutions?
Regards,
Michael
Refer this information on Android Developers website for Storage Options in Android.
You will read if you need to store large amount of data you need to create a Sqlite Database but if you need to save small amount of data then Shared Preferences will do.
Now you need to save and retrieve data from these storage options.
1) Shared Preferences Tutorial
2) Sqlite Database Tutorial
I assume till now you have done with saving and retrieving data . Now you need to match your current time with saved time in your app like a Alarm clock do. For that you need to implement a service that will tell you how much time is left in your task or what is upcoming event.
Tutorial on service.
I am developing a places of interest app which will display the list of places of interest in a location.
When user chooses one, it will display more information and address etc.
How do I store all this data? Currently I am using a text file to store all the data and subsequently when user chooses a place, it will parse the text file and retrieve the necessary data for display.
Any advice on what is a better way to do this? I looked at SharedPrefs, but it is more like storing "key-value" pair and in this case I need to store a large amount of data.
I want the info to be available even when the device is offline, thus I can't download from an online server upon request.
Any other way to do this?
You may store it to XML file using XML serializer, here is very good tutorial for learning that,
http://www.ibm.com/developerworks/library/x-android/
and it can be easily parsed using Java XPath Api. Have a look at this at parsing XML files
http://www.ibm.com/developerworks/library/x-javaxpathapi/
Use SQLite
It can store large data.
It is available offline.
All your problems will be sorted out.
Hre we have a wonderful tutorial for sq-lite
http://www.vogella.com/articles/AndroidSQLite/article.html
How about a relational database?
http://developer.android.com/training/basics/data-storage/databases.html
Take a look at Serialization. If you do not need database access, you could define a class what holds every information you need. Then, you can do the following:
when you need to save the datas, you serialize your object, dumping its content to a file, for example on the SD card
when you want to load the datas, you just load the above mentioned file, and get back everything from the dumped file
I am using this method in my app to cache some datas that would need internet access, so the user can still view it, and with proper implementation, this can work very nicely.
Use database, create table and insert all the data in it. When you need the data just fire the query, and you are done.
SQLite is fine for Android.
Depending on the type of data you want to store, you could use a SQLite Database (provided with Android) if it has a normal database structure. You could Serialize your data and save it in a raw or encrypted file, making you data implement Serializable.
Its an application that is calling the ZXing barcode reader on button push, after scanning in shows you the code and you can put in an amount (how much you want to order from that product), then you go next scan, so on so on...I need to store this data. In my main window under the scan button, i will have a show scanned list, with all the scanned items plus the amount of each. And i will have a send button which sends a this list in a .txt or a .csv file via bluetooth to PC. And after closing the application with exit button, or with the back key, this list needs to be destroyed , so when i start the application again, there is a fresh, new list. First i thought, on using SQLite, but my costumer wants a simple program, without db. I could just need a few ideas on storing, data else how. Like an array list, but i dont know how hard is it to handle such a storing bethod, with editing or deleting and such. Or directly saving it into a .CSV file? Any idea is welcome.
Thanks you.
create a Bean class say Product which contains the attributes which you want to display on your list view.
Take a ArrayList
store the bean objects in arraylist and finally iterate it to do your calculations.
To get the CSV, you can call the to string on the instance of arraylist.
IMO using SQLite would be your best option, it does not add that much complexity to your app. Though if you really do not want to use it, Shared Preferences is an even simpler API for storing data.