how to backup and restore a database from google storage in android
<p>I am trying to build an Backup and restore app that backs up text files created using Editor.I want to backup that whole database.I got some help from this link but it is not working.
<a href="http://stackoverflow.com/questions/5282936/android-backup-restore-how-to-backup-an-internal-database">Android backup/restore: how to backup an internal database?</a>
I have defined everything in Manifest file.
All the files are stored in Listview after new files are made.
I call (backupManager.dataChanged()) whenever i create a new file.
This my helper class</p>

<pre><code>public class DbBackupHelper  extends BackupAgentHelper{
 // Object for intrinsic lock
static  Object[] sDataLock= new Object[0];;
public void onCreate(){

      FileBackupHelper dbs = new FileBackupHelper(this,"mydatabase.db");
      addHelper("dbs", dbs);
}
public File getFilesDir(){
      File path = getDatabasePath("mydatabase.db");
      return path.getParentFile();
   }
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
          ParcelFileDescriptor newState) throws IOException {
    // Hold the lock while the FileBackupHelper performs backup

    synchronized (Editor.sDataLock) {
        super.onBackup(oldState, data, newState);
    }
}

@Override
public void onRestore(BackupDataInput data, int appVersionCode,
        ParcelFileDescriptor newState) throws IOException {
    // Hold the lock while the FileBackupHelper restores the file
    synchronized (Editor.sDataLock) {
        super.onRestore(data, appVersionCode, newState);
    }
}}
</code></pre>

<p>This is my Database class</p>

<pre><code> enter code hereprivate static final String INSERT = "insert into " + TABLE_NAME + " (name,content) values (?,?)";
public DataManipulator(Context context) {
    DataManipulator.context = context;
    OpenHelper openHelper = new OpenHelper(DataManipulator.context);
    DataManipulator.db = openHelper.getWritableDatabase();
    this.insertStmt = DataManipulator.db.compileStatement(INSERT);
}
public long insert(String name,String content) {
    this.insertStmt.bindString(1,name);
    this.insertStmt.bindString(2,content);
    return this.insertStmt.executeInsert();
}

public List&lt;String[]&gt; selectName()
{
    List&lt;String[]&gt; listView1 = new ArrayList&lt;String[]&gt;();
    Cursor cursor = db.query(TABLE_NAME, new String[] {"id","name","content"}, null, null, null, null,null); 
    int x=0;
    if (cursor.moveToFirst()) {
       do {
            String[] b1=new String[]{cursor.getString(0),cursor.getString(1),cursor.getString(2)};
            listView1.add(b1);
            x=x+1;
       } while (cursor.moveToNext());
    }
    if (cursor != null &amp;&amp; !cursor.isClosed()) {
       cursor.close();
    } 
    cursor.close();
    return listView1;
</code></pre>

<p>}</p>

<pre><code>public String[] selectContent()
{
</code></pre>

<p>Cursor cursor1 = db.query(TABLE_NAME, new String[] {"id","name","content"}, null, null, null, null,null); </p>

<pre><code>        b2 = new String[]{cursor1.getString(2)};

        if (cursor1 != null &amp;&amp; !cursor1.isClosed())
            cursor1.close();                
        return b2;
  }


private static class OpenHelper extends SQLiteOpenHelper {
    OpenHelper(Context context) {
         super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
         db.execSQL("CREATE TABLE " + TABLE_NAME + " (id INTEGER PRIMARY KEY, name TEXT,content TEXT)");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
    {
         db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
         onCreate(db);
    }
</code></pre>

<p>}
}</p>
