Saving edittext data in android [duplicate] - android

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

Related

how to save the data which are dynamically added in recyclerview?

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

Proper way to store mobile numbers

I am completely new to android. I am trying to build an app, where the user can save few mobile numbers.(In setting activity of the app)
And I have a button in the main activity on clicking it i need to send a pre defined message to the contact numbers which was already saved by the user.
So should I write down the numbers entered in a file internally or is there any other concept that will save the data entered by the user and use it for the apps further use
You can use SharePrefrence or Sqlite Database to save value, So that you can retrieve it later whenever required Tutorials to use are below:
SharePrefrences:
http://www.tutorialspoint.com/android/android_shared_preferences.htm
Database:
http://www.tutorialspoint.com/android/android_sqlite_database.htm
SqliteOpenHelper suits best for this case. You can store all the numbers in the sqlite database and there are number of tutorials for knowing how to use it.

Shared Preferences Vs Sql Lite Data Base [duplicate]

This question already has answers here:
Pros and Cons of SQLite and Shared Preferences [closed]
(5 answers)
Closed 2 months ago.
i am developing an apps where i have to stored 30 to 50 friend contacts, Name,phone and password, i have two option shared preference and sql lite, so which one i should use so that it got less storage and could't waste many memory and which one will be faster during searching any contacts no or item ?
You should definitely use SQLite for that kind of data and requirements.
SharedPreferences are intented for saving preferences (hence the name), not for structured data resp. large amounts of data. Also with SQL you have ways of filtering and sorting the data, e.g. select * from contact where lastname like 'A%' order by firstname to get all contacts where the lastname starts with an A and have them sorted by their first name (just for example).
I think that the best solution depends from how the app must be developed now and in the future.
If you want to develop an app that can't change in the future ( for example the contact must be ever name, phone and password ) you can use a solution "Quick and Dirty" save on the shared preferences a key-value set and don't lose any time on it.
But if the informations can change and the app can have some improvements...is more usefull to create a object contact and a data structure to manage it.
If the contacts are a few number, you don't care about the performances. 50 records direct access to the id of the user have a good performance on SQLite.
SQLite (data is complex type and data is in large amount)
SharedPreferences(data is small, data is premitive type and you don't want to share it with user)

How to save android text entered by the user?

For my newest app it it one that will save multiple EditTexts where the user can enter stuff.Like say if it was a note app,how would i get them to save?
There are multiple ways to store data on Android. Read about data storage.
In your case you might have multiple text records with some metadata (time when created, etc..), so I'd recommend the database.
Check out how to store preferences with android's "SharedPreferences":
http://www.javacodegeeks.com/2011/01/android-quick-preferences-tutorial.html
This way you can indefinitely store whatever you're working with as a string, object, etc. Also, you can check out how to work with android's SQLite Database, which might be harder to figure out when you start working with it, but it gets easier over time.

How to store data from my app

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

Categories

Resources