'where does the method SQLiteOpenHelper.getReadableDatabase() look to get the database?

The docs that come with class SQLiteOpenHelper do not say which directory its method getReadableDatabase looks to obtain the database.

I am trying to understand the need the statement on line 31 this.getReadableDatabase in the following code snippet from RIP tutorial:

01 public DatabaseHelper(Context context) {
02         super(context, DB_NAME, null, 1);
03         this.myContext = context;
04         ContextWrapper cw = new ContextWrapper(context);
05         // The line below will define the path to the database file in the apps file directory
06         // as being the internal file directory/databases/
07         DB_PATH = cw.getFilesDir().getAbsolutePath() + "/databases/";
08         Log.e(TAG, "Databasehelper: : DB_PATH is: " + DB_PATH);
09         outFileName = DB_PATH + DB_NAME;
10         File file = new File(DB_PATH);
11         Log.e(TAG, "DatabaseHelper does file exist? : " + file.exists());
12         // File file is just the directory part of entire path so file.mkdir() ensures the
13         // directory is created.
14         if (!file.exists()) {
15             file.mkdir();
16         }
17 
18     }
19 
20     /*
21      * Creates empty data database on the system and rewrites it with your own database.
22      */
23 
24     public void createDatabase() throws IOException {
25         boolean dbExist = checkDatabase();
26         if (dbExist) {
27             // do nothing - database already exists
28         } else {
29             // By calling this method an empty database will be created into the files directory
30             // of your app. We will be able to overwrite this database with our database
31             this.getReadableDatabase();
32             try {
33                 copyDatabase();
34             } catch (IOException e) {
35                 throw new Error("Error copying database");
36             }
37         }
38     }
,,,




Solution 1:[1]

Line super(context, DB_NAME, null, 1); sets the database name used that is always in your App's private "database" directory

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrew