Why database gets deleted when an apk has been reinstalled? - android

I have a problem related to the app that I developed which runs on honeycomb. When I reinstall the apk its database gets deleted. There did not used to be this almost 1 week ago. Why this is happening now? What can cause db to be deleted and how to prevent it?

I think, If your database stored in application's internal storage /data/data/<package_name>/databases/ then when your application un-installed from device, all directories with your application package are removed from the device this cause your database removed.
To prevent put your database copy in application's /asset directory so whenever your application first time runt it copy the database from asset to internal storage path. And you can access it whenever application re-installed, also you can put your database in /sdcard but user can also delete it..
EDIT: Using your own SQLite database in Android applications and How to ship an Android application with a database?
Thanks...

i guess it about checking existing database in your code. but i'm not sure exactly, it can occur from many causes. Just give an idea.

Related

Android database location in app directory

I don't understand why database files are stored in the android emulator or phone in the data folder data/data//databases rather than being stored in the application that uses it.
Logically, the database file must also be stored in the android app, right ?
If yes, where should it be stored in the app directory ?
your database will be saved under data/data/myApp/database and not in any other folder but your application folder, since database consider as a private to your app, android make it hard for people with non-root access to see your database. you still can store it in any place you like just point to it from your app.
Put your database in your assets folder, then its path is given by "/data/data/<your-package-name>/databases/<dbname>"

database and package location of Android application

I am developing Android application. I use SQLite to store data in user's device. The problem is I don't know where the database is. I also can't locate the package of my application in the device. Usually package can be found at directory Android/Data/com.example.xxx. Can anybody tell me why?
By the way I follow SQLite tutorial from http://www.edumobile.org/android/android-development/use-of-sqlite/
I have checked the code and it doesn't show where the database saved.
I use SQLite to store data in user's device. The problem is I don't know where the database is. I also can't locate the package of my application in the device.
You do not have access to internal storage on a production device.
Usually package can be found at directory Android/Data/com.example.xxx
I have never seen such a directory.
A SQLite database traditionally, on Android 4.1 and below, would be in /data/data/com.example.xxx/databases/. However, you can only get to that directory on the emulator and on rooted devices. And, on Android 4.2 and higher, the path to internal storage depends on the user account.
Your application can use getDatabasePath() to learn where your database is stored (e.g., for logging), and you can copy that file from within your app to external storage (e.g., via a Backup action bar item).

Database created from SQLite Browser not working in device "Android"

My proble is I created a device in sqlite database browser and its work fine in emulator.
but when a try my application to my device it cause force close.
and when I remove the database and create a new one using eclipse it works fine even in my device. But inserting a lot of data in database 1 by 1 realy freakin me out so anyone know a sqlite database browser that also work for device??!
check out this tutorial for using database file in application.
Remember one thing that it only copy you DB file in application that's it.
On real device you don't have permissions to sqlite database. That's why you won't be able to browse database like you can on a emulator.
See this for a work around.
Tool to see android database, tables and data
If you want to create a pre-loaded DB outside of your app and use it in your app later, you will have to put it in your assets directory and then copy it to your apps storage space the first time your app is started.
This is due to the fact that as a security measure, on real (unrooted) devices nothing but your own app is allowed access to that apps databases directory (and certain other ones as well).
There is a good tutorial for creating/copying your own DB outside of the app and copying it to the apps databases directory here.

Android database on phone

I have a problem regarding android database.I have an app which have it's database in assets folder.This app is already installed on the phone and working fine.But now i created another database file(just increase the number of records in the previous database and everything else is same). And put it again in assets folder and replace it with existing database file, and recompile the project. Now in emulator the new database is loading and showing the updated content in database. but when i installed the app again in phone my previous database is showing up and new database is not loading.
But if i uninstall the app from the phone and reinstall it then new database is showing up.
PROBLEM: I just want that if i replace the preexisting app on phone the new database should be loaded, not after uninstalling and then reinstalling the app.
Any suggestion or help?
In Android you must use the onUpgrade function to update your database from a previous version. This is because Android will only create your database once and from then on out it will just use that one. So you must assign a version code to your new database that is different from the old one and use the onUpgrade to actually perform the change to the new database. All devices that are installing from scratch do not have a current database so they are getting the new one created for them.
I bet if you clear the data for your app in Settings and relaunch it, it should load the new database. The reason for this has something to do with SQLiteOpenHelper copying the database from the assets folder in the APK to the application's data directory on the phone if it doesn't already exist. Otherwise it will load the one on the phone. Unless you specifically access the database from the assets folder each time, it will use the cached version.

Does uninstalling of an android app delete the database stored on sdcard?

I have a library app where I store each book as an SqliteDatabase. I save all the book dbs on sdcard. My question is if user uninstalls my app, then do all the dbs related to this app get deleted? If no, how can I achieve this?
Thanks.
Generally No actually. When you uninstall, the APK itself (/data/app/com.example.app-1.apk) and the data (sharedprefs/db/etc) in /data/data/com.example.app is removed, but only Android >= 2.2 will also delete anything from the sdcard, and only a specific directory getExternalFilesDir() (/sdcard/Android/data/com.example.app usually).
However some earlier versions of Froyo will also delete when updating an app, which makes it rather dangerous to use for persistent storage.
It depends. If you put your files on some arbitrary place on external storage (SD card), they will not be deleted after you uninstalled your app. If you used getExternalFilesDir() (Android 2.2+) to get the directory to store your files in, they will be deleted when the app is uninstalled. On some early versions of Froyo, there is apparently a bug that deletes the files even on app upgrades, so you might want to watch out for this.
answer is Yes.. everything is removed.. including SharedPreference and db.. You need not implement it by yourself.. for more red this.. http://developer.android.com/guide/topics/data/data-storage.html

Categories

Resources