Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Database Android

Tags:

android

Can anyone tell me how to update the database in android. I created an app with an embedded database. I changed the version of the database in the manifest and created the on update method. I wanted to test it to see if the database was updating properly but when I use the adb command only the -r will allow me to do a reinstall but it keeps the database. Is there a way to run the adb command that will allow me to update the database. Thanks.

like image 472
user237259 Avatar asked Jan 19 '10 22:01

user237259


People also ask

What is a database in Android?

A database for Android is a form of persistent data storage intended for use in apps for Android devices. It often consists of on-device, local storage so the app continues to be available even if the device loses connectivity.

Which local database is best for Android?

PostgreSQL. A unique relational database, PostgreSQL is the best database for Android and iOS apps.

What is the built in database of Android?

Android comes in with built in SQLite database implementation.


2 Answers

Here is how I would handle my updateRow method:

public void updateRow(long rowId, String code, String name) {
      ContentValues args = new ContentValues();
      args.put("code", code);
      args.put("name", name);
      db.update(DATABASE_TABLE, args, "_id=" + rowId, null);
}
like image 173
hassanadnan Avatar answered Sep 21 '22 12:09

hassanadnan


What worked for me is changing the version number for the database. This is the constant number that is used by the onCreate() method of your content provider. Something similar works if you don't use a content provider for your database, and query it directly. See source code example here.

like image 42
r1k0 Avatar answered Sep 19 '22 12:09

r1k0