I have android application, I use SQLite data base in my application, I have a question about data base in setting -> application manager if I select clear data or clear cash, our data base deletes, but I need data base. For example user remove data base suddenly after that my program does not work, my program is related to data base, how do I do, how can I resolve my problem?
You will need to find some way to backup your database to the SD card. You could just dump it as a CSV-type file, which would exactly mimic the structure of a database, or else create some other kind of format which would work better for you. And then in the case that the database is cleared, you will need to parse the text file you created as the backup, and put it all back into the database.
Related
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.
I have an issue of saving app data internally on device, Well this go like below:
App is service based. We send a request a for particular home project and it will respond with an image of the project and a list of operations. And they want every link to be clickable and on click of that show more links with some text and images. Means lot of data to be handle.
The data which store internally should also get updates. So what could be the better option of saving it. Download files, download more files when update is required or go with SQLite database, which will update the existing db only.
Till now I am finding to create sqlite db as a better option, but still I want to know which could be the better option. I know this would create a memory issue, but this is what client want.
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.
I am working on some application, where I am storing some of my application data in SQLite DB. If any user clears the data, my data gets cleared. Through How to disable the Clear Data button in Application info of Manage appliaction and http://groups.google.com/group/android-developers/browse_thread/thread/b1091f190f7356b7 these links, I found that we cannot disable clear data button, But my question is Is there any way to catch this action(clear data) in the application? Is there any intent in android to notify this action ?
Thanks in advance
Pushpa
A possible workaround is to program your application to use a SQLite database on external storage. SD card etc. just create a folder on your SD or whatever storage you want, place the .db file in that folder and use that instead of the default storage location. By default, SQLite databases are stored in the data folder(device not rooted so dont know where in the data folder), which is not accesible unless you rooted your device.
There are tutorials out there that use this technique.
Note that, its likely that when you delete your app, the data will persist.
Don't know if that is desirable.
You can do one thing You can create a test table in your DB and insert some data in it. Every time you run the application you check the value of the table exist or not. If data exist that means DB value is not reset and if Table is empty you get to know that DB data is cleared and insert the data again for the next time check.
I want to clear data through coding for my application. Right now I am Clearing Data from Settings->Applications->Manage Application->My Application->Clear Data.
But I want to do it through coding.
Please help me if any one have answers.
Use Context's getFilesDir method to get the directory, and then delete all directory and data as explained here.
Using MByD's code to delete a dir, delete the folder /data/app/my.app.name ;-)
If the data is "Internal" to the application, it generally can't be cleared from any other app. I did read that you want to clear data of your app through coding but it wasn't clear whether you want to clear data from the same app.
You need to change the same application's code and instruct it to delete the data. But, if you're clearing from the same application you might want to specify which database table or file, for instance, you want to delete instead of just clearing all the data.
You'll find application data here: /data/data/packagename.appname/
Use this to delete the application files: deletefiles()