android bestway to keep temp data - android

hi in my application i have temp data , i need to keep the data only up to a particular condition , when app meet this condition,i don't need the data anymore. my problem how to keep the data,upon resuming the application

Using shared preference is the best way

You could try storing data in a sqlite database - there are lots of examples around the internet about how you can use sqlite database in an android application :
http://developer.android.com/guide/topics/data/data-storage.html
http://www.screaming-penguin.com/node/7742
or, you could store stuff in xml files
http://www.ibm.com/developerworks/opensource/library/x-android/
if you store data in xml or an sqlite database - the data is persistent until you specifically remove it.

Related

Which file type should I use to store database data

I'm developing a little Android app which is going to be offline, and I need to store the SQLite base's data into a file, that I want to put into the apk's resources, I could use XML or JSON files, but I was wondering if there weren't a better solution.
Thanks in advance :)
If I understand you right you have some prepared data to include in app to use.
If you don't want to parse xml, json or raw file every time you need it in the app you could:
1. Parse the file and put contents into SQLite database on the first run of the app.
Then you can use SQLite to query for data.
You can check if this is first run by checking boolean flag in SharedPreferences upon start of application (in onCreate of your main activity or in Application class)
2. If data is not very big you could parse it once and keep it in memory in your custom data structure.
You can create a singleton to query for this data and parse it in case it is not loaded yet.

Storing a large amount of backend data in Android

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.

Android how to keep static data on application relaunch?

I am having an abstract class having all static objects and function to store some globel data of the application during the execution session.
All data reset to null once I relaunch the application in ICS and above version with Systems's setting ALWAYS_FINISH_ACTIVITIES is set as true.
Whats the better way to mainitan data on application relaunch?
Regards,
Android IT
Editing my question:
I know that Sharepreference can be a better option but I dont want to store data for multiple sessions of the application and data I am storing is huge.
Regards,
Android
IT
Each Android app is running in a dependent process. When an app become background and system need memory, the app's process may be killed by system. In this situation, when app relaunch, static objects will lost.
I think use SharedPreference to maintain data is a better way.
You can store data using SharedPreferences
http://developer.android.com/reference/android/content/SharedPreferences.html
Store the data on the local storage would seem appropriate: http://developer.android.com/training/basics/data-storage/index.html
You can store the data local using a XML file. You can read the XML File on startup with a DOM Reader
http://www.ibm.com/developerworks/library/x-android/
If you have lots of data you can use a SQLite Database
http://developer.android.com/training/basics/data-storage/databases.html
If there are not too much data you can keep them in SharedPreferences
You access them with PreferenceManager.getDefaultSharedPreferences()
Once application exit or destroy that will remove all data . if you want to access after relaunch you should save your data as per your requirement . like local or web. its deepen you. right now you can store data in preference so it will useful after relaunch the application.
I think this is better for you : How to use SharedPreferences in Android to store, fetch and edit values

Android Preferred Storage

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 .

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