We are developing an application in android,We have to save some lists and data to be used by application.We have saved it in sqlite and we use that data by using cursor.
Now my question :
What is more efficient to store data in we should continue with sqlite or to store data on strings.xml or we should use shared preferences ??
Sql Lite is for sharing your data as a datasource. It does not make sense
otherwise as you have the overhead of writing queries to serialize your objects.
Shared Preferences is a preferred way to store internal data.
You can't use assets as said by someone else before because its read only.
Well It Depends on your requirements. If your requirements are dynamic then you should try Sqlite for Storing the Datas.
You should use String.xml to store constant strings, which are not going to change easily ( i mean by increment or decrement of Strings ).
In your scenario, I think best way to store is in asset folder. Means store that data in txt file in key-value pair and while displaying in list, your just have to read that and display in the list. So that saving step can be avoided.
Shared Preferences are generally used to store primitive data. I'd suggest you to go with SQLite .
Related
I want to use sharedpreferences in my login form, but i also want keep XAMPP as my main storage. What is the best data storage when I want to do my app in offline mode?
Yes, you're allowed to mix and match any type of data storage you wish because none of them were designed to be in conflict with each other.
However, it's a good idea to understand what type of data storages is available for you to use, because different types of storages has different benefits and drawbacks.
SharedPreferences is a great way to store a user's preferences, or simple data with a single value. It's great for storing a user's preferences because when creating Settings, it's extremely common to use Preferences which directly reflects the values within your SharedPreferences. However, due to it's design, SharedPreferences isn't a good idea to store large amounts of data or dynamically created data.
For that, it's better to use a database and you're free to use any type of database you wish. But for offline mode, it's best to use the SQLite Database that's offered by Android by default.
However, if you do want to use XAMPP, it's not uncommon to see developers who store their full data in an online database, but cache a few data within a local database like SQlite.
Therefore, there's zero conflicts among data storage options, so mix and match to what benefits your app's design best.
If you want to store data in locally then you can use SQLite Database and yeah XAMPP is whole different thing to store data for this you need to create APIs to communicate with database.
You can also use Sharedpreferences for storing the data but Sharedpreferences will store data with the key-value pair only.
But you can use both for different different purposes for the same app
I need to store some config predefined information in my Android app such as the list of the servers, logins and passwords. This information should be stored permanently and be editable. For some reason, I think SharedPreferences isn't what I'm looking for. Maybe using internal Android SQLite db would be better?
What do you think?
You can store predefined data in a .db file under R.raw and copy it to your app's working directory then use it with SQLite.
You can specify these setting values in program as variables and insert in sqlite on first launch of application, By this way you can edit these values later in sqlite, I hope this can help you.
I have generally found SharedPreferences to be more easier to implement (also demands less resources than any kind of database). In your case, in my opinion, you should go for SharedPrefences, by loading your required information on first launch through some predefined keys, example, URL + i, where i can be run from zero to the number of URLs. This can be then later retrieved and edited. You can save the initial values in arrays as suggested by others above.
I have to store some data (string) in my Android app and I'm a dilemma. What is better solution ? Use Set Collection and keep it at SharedPreferences or I should save data to File and when I need it I have to read data from file and put it for example on ArrayList.
Depends on the quantity & complexity of the data. There is no straight answer to your question.
General approach: If the data are not too sensitive, small in quantity and more frequently used then you should go with SharedPreferences.
If your data is quite large lets say few hundred KBs of String then you should go with File.
SharedPreferences ultimately stores data into a file. The advantage of using SharedPreferences is that, the data is stored as a key value pair and can be retrieved easily using a key.
It depends on what you want to store.
Use SharedPreferences when you want store simple, prmitive data. Keep in mind that SharedPreferences will be available only for your app, so anothers apps cannot get data from it.
Use File when you have more complex data. You have to take care about how file is available to others. If you put it in sdcard root directory for example it will be available for everyone. If you put it in app package it will behave like SharedPreferences.
In my android app I receive data as json like this:
"_playLists":[{"name":"Playlist 1",
"items":[{"name":"Poza 1","target":"...","url":"...","url_thumb":"..."},
{"name":"Poza 2","target":"http:\/\/audifrance.fr","url":"...","url_thumb":..."}]},
{"name":"Playlist 2",
"items":[{"name":"Poza 3","target":"...","url":null,"url_thumb":null}]}]}
My question is : which is the best way to save data from this response: using Shared Preferences or using a database SQlite? Is it possible using Shared Preferences to make connections between the saved data?
If there is no security concern with data, data is complex type and data is in large amount I think SQLite is the best for it.
And if the data is small, data is premitive type and you don't want to share it with user then SharedPreference is good.
Choice is yours.. Thanks.
both have different purposes .
for small sized primitive data's where you don't want to invoke any queries use shared preferences .
for large sized , complex type storage , use sqLite
Actually i want to know how to store data from my app in the device so that i can review the store data when i run the application again..
means in simple terms i want to say that suppose i have text box where i write some information..now when i click the submit button, this information will be save,so that when i open the application the stored data should be appear in the text box..
In all terms i want to say that i just want to stored data in the way that we are using database for storing data..so please anyone suggest me how that can be done in android.
if possible show with an example
Regards
Anshuman
If you have to store small amount of data, you can use SharedPreferences in Android.
If the data that you have to store is big/complex enough, try using SQLite database.
Still need help?
UPDATE: There's a tutorial that I wrote to demonstrate how to use SQLite database. check it out here. Although it copies existing database into device's memory, but other versions of it, which create database through code can also be devised from it.
A better tutorial is here : http://www.vogella.com/tutorials/AndroidSQLite/article.html
1) If you want to store data in table format then you can use SQLite database in android
2) If you don't want to store data in table format then you can store in SharedPreference
more info about SharedPreference here and here
Android comes with a built in SQLite database that you can use. I advice you to go trough this notepad tutorial. It teaches the basics of using Android SDK including different states of the android application as well as how to use SQLite with Android.
For storing simple key = value pairs, you can use Properties.
For data storage as in a database, you can use sqlite on android.
Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs, such as whether the data should be private to your application or accessible to other applications (and the user) and how much space your data requires.
Your data storage options are the following:
Shared Preferences
Store private primitive data in key-value pairs.
Internal Storage
Store private data on the device memory.
External Storage
Store public data on the shared external storage.
SQLite Databases
Store structured data in a private database.
Network Connection
Store data on the web with your own network server.
Data Storage