3

I have a backups module in my that restores the SQLite database from a backup. First, it removes the current database file and then copy the backup database bytes to the database directory. Once database is restored, I ask for the user to restart the app, including remove it from memory. This is working properly.

Is there a way to "refresh" the reference to the database file programatically? In this way, user has not to close the app.

My database is stored in /data/data/com.mypackage.project/databases/mydatabase.db and the backups are in sdcard.

I restore the database file like this:

public static boolean transferBytes(File from, File to) {
        FileChannel inputChannel = getInputStream(from).getChannel();
        FileChannel outputChannel = getOutputStream(to).getChannel();
        return transfer(inputChannel, outputChannel);
    }

private static boolean transfer(FileChannel inputChannel, FileChannel outputChannel) {
        try {
            outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
            inputChannel.close();
            outputChannel.close();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

Where from is the backup file and to a file instance with the database path mentioned above.

1 Answer 1

1

Did you try to create a new instance of DBHelper after restoring db?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.