1

I want to add ability for users to backup application database and settings to SD card. Then should be able to restore all data on another device.

How usually these tasks are done? I need recomendations/samples.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
barbarian
  • 1,559
  • 6
  • 20
  • 26
  • The Android Backup system should help you: http://developer.android.com/guide/topics/data/backup.html – Benoit Sep 23 '13 at 13:56
  • Android Backup system store data on the cloud and only if user enable this option. I want to store all data on SD. – barbarian Sep 23 '13 at 13:58
  • Implemented db import/export based on this thread http://stackoverflow.com/questions/6540906/android-simple-export-and-import-of-sqlite-database/6542214#6542214 – barbarian Sep 30 '13 at 14:32

3 Answers3

3

With Database you basically have two options.

  1. provide option to user to backup database to a sd card.
  2. create/uses database from SD card

Case 2

You can use getExternalFilesDir() to store your app data. This will create a folder on SD card with your app name.

How to use standard SQLLiteOpenHelper with custom path read this link. A nice answer at the bottom. Alternatively you can directly open your DB from SD card using openDatabase function. This function just required path to the your database.

Case 1,

if you are copying database to sd card, which basically a regular file copy and in this case do simple file from one path to another. getPath() from SQLiteDatabase will give you path of the database.

Shared Preference With Shared preferences, which support only key values, and how to access shared preferences from a SD card read this link.

Community
  • 1
  • 1
minhaz
  • 4,233
  • 3
  • 33
  • 49
  • I Implemented db import/export based on this thread http://stackoverflow.com/questions/6540906/android-simple-export-and-import-of-sqlite-database/6542214#6542214 – barbarian Oct 03 '13 at 08:23
0

Here is a question with many good answers about backing up databases to an SDCard: How do I backup a database file to the SD card on Android?

with the following example: http://mgmblog.com/2009/02/06/export-an-android-sqlite-db-to-an-xml-file-on-the-sd-card/

Community
  • 1
  • 1
Mdlc
  • 7,128
  • 12
  • 55
  • 98
0

What is your application all about? I would solve this problem different.

Instead of allowing users to reload their settings from a sd card, create support for user accounts and a server to allow users to synchronize their profiles on log in.

Johnny Z
  • 14,329
  • 4
  • 28
  • 35