1

I am developing an android app in Xamarin(C#) using SQLite database. But the issue is every time I install the application on emulator or mobile phone, the old database is deleted.

Is there any way I can make database permanent? I want it to be present on the device even the application is uninstalled assuming that the user will be re-installing the app again. How do I ask user if he/she wants delete everything while uninstalling the app and then erase all the data or maintain at least the database if user does not want to delete everything?

3 Answers 3

2

It's not possible to keep a database if you uninstall the app.

Sign up to request clarification or add additional context in comments.

Comments

0

Is there any way I can make database permanent?

Short of a custom ROM of some sort, nope.

How do I ask user if he/she wants delete everything while uninstalling the app and then erase all the data or maintain at least the database if user does not want to delete everything?

You won't be able to prompt the user as they are deleting applications to perform some other action. If this was an option that was available, unscrupulous developers could use such a hook to reinstall their application in a different location and this is bad.

You could, however, include some sort of preference that allows the user to backup their data and copy the database to a location out of your apps private directory. Of course, you would have to provide your own way of encrypting the data if it should be private, and there is no guarantee that the file will not be deleted by the user, another app, etc.

If your information is not sensitive in nature, perhaps writing the database to a public directory (anything other than your application filesDir or externalFilesDir from the start is the way to go. Files in public directories are not deleted when the application is uninstalled.

You may have a greater problem though. If the user is switching devices, a local copy of the database isn't going to help. You'll need someway to download the information and restore state. At this point, most people resort to sending the information to some sort of web service. Android's Backup Manager may be helpful in your case.

1 Comment

If the temporary problem of losing the data while developing is an annoyance, you may be able to use the comments on this question to help with Xamarin uninstalling and reinstalling the app on each deploy.
0

When you launch the emulator be sure "Wipe User Data" is not checked. This will allow the data to persist while you are testing. I don't know if it is possible to keep data after an uninstall because it is by default stored in a directory off the application root called data/data

1 Comment

I made sure that... Everytime I make change I do deploy or press F5. The application is removed and installed again on emulator...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.