title: How to recreate SQLite Database at runtime when using Room in android
body: <p>I want to nuke the database and recreate it at runtime. 
  I used this in base activity to nuke the database and it successfully did it 
  <code>deleteDatabase(AppDatabase.getDATABASE_NAME());</code></p>
  
  <p>I then used the following code to clear all back stack and open the launch activity</p>
  
  <pre><code>Intent intent = getBaseContext().getPackageManager().
  getLaunchIntentForPackage(getBaseContext().getPackageName());
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(intent);
  </code></pre>
  
  <p>Now when I try to insert into database via Room it throws the following error</p>
  
  <pre><code>android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032)
  at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
  at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782)
  at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
  at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
  at android.arch.persistence.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:80)
  at android.arch.persistence.room.EntityInsertionAdapter.insertAndReturnId(EntityInsertionAdapter.java:114)
  at xx.yy.data.local.db.user.UserDao_Impl.insertUser(UserDao_Impl.java:124)
  at xx.yy.data.local.db.DbHelper.saveUserDetails(DbHelper.kt:51)
  at xx.yy.data.DataManager.saveUserDetailsToLocal(DataManager.kt:101)
  at xx.yy.data.DataManager$signUp$1.call(DataManager.kt:146)
  at xx.yy.data.DataManager$signUp$1.call(DataManager.kt:29)
  at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
  at rx.internal.operators.OperatorMerge$MergeSubscriber.emitScalar(OperatorMerge.java:511)
  at rx.internal.operators.OperatorMerge$MergeSubscriber.tryEmit(OperatorMerge.java:466)
  at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:244)
  at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:148)
  at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
  at retrofit2.adapter.rxjava.CallArbiter.deliverResponse(CallArbiter.java:118)
  at retrofit2.adapter.rxjava.CallArbiter.emitResponse(CallArbiter.java:100)
  at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:46)
  at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24)
  at rx.Observable.unsafeSubscribe(Observable.java:10256)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
  at rx.Observable.unsafeSubscribe(Observable.java:10256)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
  at rx.Observable.unsafeSubscribe(Observable.java:10256)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
  at rx.Observable.unsafeSubscribe(Observable.java:10256)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
  at rx.Observable.unsafeSubscribe(Observable.java:10256)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
  at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
  at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
  at rx.Observable.unsafeSubscribe(Observable.java:10256)
  at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
  at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:230)
  at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
  at java.lang.Thread.run(Thread.java:761)
  </code></pre>