Changing package name but keeping database on Android - android

I've created an Android application which has a certain package name that I've been using personally for months now. I'm about to release it on the market, and I have to change the package name. This cannot be avoided.
My issue is that the application has an SQLite database attached to it that I want to keep, but I know if I change the package name, it'll install as a separate application and I'll have to restart my database, which would take a very long time.
Is there a good way to change a package name while maintaining the SQLite database? Or at least moving the database easily? This will just be for my own phone since it hasn't been released to the public yet.

Step #1: Add a backup/restore function to your app, that copies the database to/from the SD card. Be sure your SQLiteDatabase and SQLiteOpenHelper objects are closed first.
Step #2: Install a copy of this app, built with the old package, to your phone, and use it to back up your database.
Step #3: Install the production copy of this app to your phone and use it to restore your database.

For anybody wanting to do the same thing, I've written out how to do backup/import/restore of a database and included a whole class for doing it at this link:
http://www.hxcaine.com/blog/2010/09/14/backing-up-importing-and-restoring-databases-on-android/

Related

Android SQLite app, preparing for production

I have an Android app where I use a SQLIte DataBase. I am using the app and the DB is already big. Now I want to give this app with its DB to my coworkers. Where and How to put the DB for release? I have the DB in my phone but I need it in assets folder. I was trying but it doesn't work. I tried to copy the DB directly however I read that Android compress files in that folder. Please, any solution, thank you in advance.
http://blog.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Visit this link. It contains the easiest and well described answer for your question.
You can use emulator Like GenyMotion and any other emulator. Run your app on emulator then just go to Android Studio->Tools->Android Device Monitor Then select the emulator and in the file Explorer you can find your db file . and then export from the device and export to your desktop. here you can give it to any one.
You can use your own SQLite database by adding it to assets folder. The best way is to use Android SQLiteAssetHelper. Better than reinventing the wheel.
Here the excerpts from its readme:
An Android helper class to manage database creation and version
management using an application's raw asset files.
This class provides developers with a simple way to ship their Android
app with an existing SQLite database (which may be pre-populated with
data) and to manage its initial creation and any upgrades required
with subsequent version releases.
It is implemented as an extension to SQLiteOpenHelper, providing an
efficient way for ContentProvider implementations to defer opening and
upgrading the database until first use.
Rather than implementing the onCreate() and onUpgrade() methods to
execute a bunch of SQL statements, developers simply include
appropriately named file assets in their project's assets directory.
These will include the initial SQLite database file for creation and
optionally any SQL upgrade scripts.

Completely erase all traces of database schema for practice in Android

I am not new to Android or Java but very new to Databases. I have been practicing with SQLite in Android and have now become completely stuck.
I want to completely remove the current database that I have been using in my app and create a new one with more columns, different types of columns, and etc...
I have tried "context.deleteDatabase()" which appears to delete the database but then after that I uninstall the app and re-install it with the myDatabaseHandler java class file having all the new columns and changed added to the file.
The code compiles and runs fine until I try to add info to the database, I receive an error cannot find columns, the error refers specifically to the columns that I added.
Why does it seem that I cannot start over completely. It seems like the structure or schema of the database won't change.
So how do I eliminate any evidence of the databases that I was practicing and messing around with, and just start completely new? After all, thats what practice is, you don't know what you are doing and you learn by making mistakes. So now I need to completely wipe away the mistakes, not upgrade just to make alterations.
Upgrading the database seems to provide an avenue for achieving close to what I want, but ultimately is way more involved and confusing for what I need when I just need to start over with a freshly created databases that has more columns.
The SQLiteOpenHelper class goes to great care to keep the old database to allow you to upgrade it in place.
If you're not interested in the old data, just change the file name. Then it is guaranteed that there is no old version. (You still have to call deleteDatabase() to get rid of the old file, but now that call cannot conflict with any accesses to the new file.)
Using the ADB tools from the SDK/platform-tools folder can help to remove all data (including the database schema)
./adb.exe -s shell pm clear <your app's package name>
will remove all the data associated with your app. Then you install the new version of the app, it will use the new database schema.

Using a pre-built db4o database in android app

Im REALLY struggling to get a pre baked db4o database to work inside my android app.
If i include it in the /res/raw folder then read it, it doesn't work.
If i copy it to the app_data or sdcard then try and read it, it will act as if im opening a new database and provide me with 0 entries on queries.
I was previously just creating all my entries when the app was first opened but as the db grew, so did the creation time to unsustainable levels.
I would really, really appreciated any help you can give me. It would be perfect if i can include my pre-populated db4o file in the app.
Additional Info:
I have double checked the db4o file with ome and theres no issue with the db creation on my local machine.
Thanks in advance.
If any one falls into the same trap as me here's the answer:
On android the class is injected into the db4o db with the package name prefixed to the class name by defualt. So accessing from another application will look be looking for +.

Issue related to upgrading application related to Database in Android

When i modify the database and upgrade the existing app in my Phone, the DB is not getting overwritten which makes my application crash.
How to tell phone to delete the DB and add fresh one during installation of APK file?
Did you try to increase the version number you pass to the the SQLiteOpenHelper constructor.
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html

Why updating an android app can make it appear twice?

I made a lot of changes to my app : databases scheme, graphics, code, etc. The biggest is the package name that I renamed to a total different one. The applicatgio got the same name and Id in the manifeste.xml file and the apk got the same name, with the same digital signature.
Nevertheless, when using ./adb install -r myapp.apk, myapp appears twice in the menu. Of course since the DB is stored in a directory using the package name as name, the user feel like its data is lost.
How can I prevent this from happening, and if I can't, how can I automate he migration ?
I have several clues : prompting the user for uninstalling the old app, copying the database from the old file to the new one, etc.
The direct answer is the application appear twice because Android Market and Android OS view two different packages as two different applications. The code can be same, but if the packages are different the applications are completely different
Android Market identifies applications by their package name. I suspect this is because the OS tracks programs by package...makes sense that you wouldn't want two packages with the exact same name installed, how would the OS know which one to call? Therefore, if you install a package with the same name as a package that's already installed the OS will view it as a package upgrade and let the new program access the old user data.
You state that the packages share the same ID, I assume this is user ID. This enables you to share data between the packages. More information is here:
http://developer.android.com/guide/topics/security/security.html#userid
Recommendation: Release a small upgrade to your old package providing whatever glue is needed to let it share it's data with your new package. Then release your new package with the code to import the user data from the old package (need same UserId and signature). The transition would be seamless to the user (no manual backup and import).
The application signature must be the same. If you imported the project in another Eclipse, build it and upload it to market you will see 2 separate apps.

Categories

Resources