How do we know when our application data get cleared in android? - android

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.

Related

reusing Room or SQLite database in the app?

I'm trying to figure out an android app that stores user's data in a database on sdcard.
But I don't know if it's possible to have these too:
even if the user deletes the app, the db remains and the user can access it.
So later they can re-install and give the app the path to the db file. The app uses that file as a database again.
Something like WhatsApp db, but the user must have the database as a file on their phone so they can transfer and store it anywhere. The data is large so it's not a good idea to get a backup file.
Is it possible to create it with Room or SQLite? and reuse it again?

How can I handle updating the database in my application and at the same time retaining user scores and settings?

I have a phone application that uses a database of words and tests a user to see which words they know. I have a SQLite database with the words that I populate using a console application and this is then deployed as a resource to phones etc.
When the user runs the application then it stores pass fail data in the same database but in different tables.
When I update the application a fresh copy of the words database is installed on the phone and all the user data is lost.
How is this typically handled? Do phone applications that use SQLite have multiple databases with one being used to store user data and the other holding data which can be brought in when the application is first installed or updated?
If multiple databases are used then is it possible to create a look up from one database to the other?
Thanks in advance for any help, advice or links that point me in the right direction.
I would use a file (JSON, or plain text) to ship the words with the app. Then, when the app runs, it reads that file and adds the new words to the database. This won't affect the other tables.
Instead of having to deal with that, we hard code the values into a static method in code. Then at runtime, we see if there is any data in the table and, if not, we grab the hard coded data and do an insert.
In your case, I would also just add a version number of some kind so then, if the version was lower or the table was empty, you do a delete all and then insert your new static data.

Clear Cash in android application

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.

Sqlite Database deleted when I clear data from Application

I have created Sqlite database in app. when I clear data from settings->applications->manage applications the Sqlite db removed. any suggestions to keep sqlite database as it is.
When you press Clear Data from the Android application manager its supposed to remove everything related to the app such as preferences, databases, caches etc the only thing that gets left is the app so when you re-launch it behaves as if it was just installed.
If you want to allow the user to clear the data but keep the database then there should be an option in the menu that removes the shared preferences but doesn't do anything with the database.
Hope this helps.
Android's SQLite is intented for local app data storage. When you opt to wipe your app's data, this data is wiped (as expected).
If you want to persist DB data, look into external storage (eg. the late Parse.com, or MS's Azure). You'll be making network calls, your local data will still be wiped, and you'll need to have a way to link your app back up with the external data post-local-wipe (eg. logging in) but your external data will survive an app data clear.
The "linking up" part can be mitigated as well depending on your use case, eg. Google Play Games' data services is tied to your Google Play id and will resync after an app wipe.
Why would you want to keep the data when the user wants to clear everything.
It is not suggested you keep the db.
I would suggest you use the sd card to store images/text files with the adequate permission from the user.

Clearing Application database

I have an Android application which uses sqlite database to store textual data for a particular user. The data is read/written from/to the database from a service that runs periodically after every n seconds. My requirement is to clear data depending on age. Like, if the file is more than 24 hours old it should be deleted.
Checking the age of the file seems easy, just compare current time with the File creation time. The problem is:
where should I put this check and delete the file; inside application onCreate() or when the user logs in/ logs out? What would be an ideal place to trigger this logic from? Should I schedule an Alarm when the user logs in?
Should I delete the file or simply delete the rows? If I don't trigger the Cache clearance logic from login/logout, won't deleting the file cause problems, especially if the service is still trying to read and write from the database?
Please advice.
Thanks.
Well, this all depends on your logic for the application for the second part. I cant see why you would delete a database unless its just used to store temp data that does not matter. Either way the ideal place to do this check and delete is in the Data Access class thats opening the connection to the database. Below would be my logic...
Call to open DB
Check if DB file is old
If yes, delete it
Open Database (should create one if it does not exist)

Categories

Resources