title: Android P (9, Pie) SQLite empty database created before copy from assets folder
body: <p><strong>An empty database file with the same name exists BEFORE we copy it from the assets folder.</strong> </p>
  
  <p><strong>android.database.sqlite.SQLiteException: no such table:</strong> </p>
  
  <p>This error message is legitimate because an empty database exists in our data directory with the same name. Although we have not copied it yet.</p>
  
  <p><strong><em>How is our database file being created?</em></strong></p>
  
  <p><strong><em>Why does it exist even if we have not called or instantiated our Database Helpers?</em></strong></p>
  
  <p>Using the same SQLiteHelper classes for all previous versions with no issues.
  Running on Android 9 Pie causes this error message after a clean install of our Android app that uses an existing database in the assets directory. Normally when this file does NOT exist in the data directory it is copied then opened. </p>
  
  <p>Checked and rechecked, the file exists BEFORE our call to move it from our assets directory. </p>
  
  <p>When checking the Android 9 Pie data directory, our SQLite database file already exists. This is after a new install AND clearing cache &amp; data </p>
  
  <p>To repeat what we are seeing.</p>
  
  <ol>
  <li>Settings… Apps &amp; Notifications  </li>
  <li>Select our app  </li>
  <li>Storage  </li>
  <li>Clear Cache + Clear Storage  </li>
  <li><p>Uninstall the app.</p>
  
  <p>Launcher Activity "SplashActivity" onCreate()</p>
  
  <pre><code>String mName = "myawesomedatabase.db";
  String mDatabasePath = this.getApplicationInfo().dataDir + "/databases";
  
  
  File file = new File (mDatabasePath + "/" + mName);
  Log.i("DATABASE", "##### SplashActivity.getData() " + mDatabasePath + "/" + mName);
  if (file.exists()) {
     Log.i("DATABASE", "##### SplashActivity.getData() FILE EXISTS!!!");
  
  }
  </code></pre></li>
  </ol>
  
  <p>Repeating the above and NOT uninstalling the app, copies the file properly. It is ONLY on new installations.</p>
  
  <p>We have confirmed we are not hardcoding the data directory. Researching this we learned that the database directory has changed.</p>
  
  <p>From: /data/data/com.___._____/databases/</p>
  
  <p>To: /data/user/0/com.____.____/databases/</p>
  
  <p>Referencing this article that helped this discovery.
  <a href="https://stackoverflow.com/questions/50476782/android-p-sqlite-no-such-table-error-after-copying-database-from-assets">Android P - &#39;SQLite: No Such Table Error&#39; after copying database from assets</a></p>
  
  <p>Work around:</p>
  
  <ol>
  <li><p>Clean install of the app. </p></li>
  <li><p>Wait for crash</p></li>
  <li><p>Settings... Apps... Specific App... Clear Cache + Clear Storage  </p></li>
  <li><p>Run app again</p></li>
  <li><p>Success, database does NOT exist in data directory, then the app copies file from Assets Directory with no issue.</p></li>
  </ol>