title: Android Firestore: Failed to gain exclusive lock to the Firestore client's offline persistence
body: <p>I'm working on an Android application in which I update user's location every 10 seconds. For this, I run a timerTask in a Service and write LatLng values to Firestore database.</p>
  
  <p>The following is my timerTask class.</p>
  
  <pre><code>class UploadDataTimerTask extends TimerTask {
  
      @Override
      public void run() {
          // run on another thread
          mHandler.post(new Runnable() {
  
              @Override
              public void run() {
  
                  Log.d("TAG", String.valueOf(mLatLong));
  
                  mFireStore.collection(Constants.LOCATION_REFERENCE).document(mUser.getUid()).set(mLatLong).addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                      @Override
                      public void onComplete(@NonNull Task&lt;Void&gt; task) {
  
                          if (task.isSuccessful()) {
                              Log.d("TAG", "Upload successful.");
                          }
                      }
                  });
              }
          });
      }
  }
  </code></pre>
  
  <p>However, I get the following error when I try to write this data to Firestore.</p>
  
  <pre><code>FATAL EXCEPTION: main
                                                                                      Process: com.sarthak.trackit.trackit:my_service, PID: 24286
                                                                                      java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
                                                                                          at com.google.android.gms.internal.zzeux.run(Unknown Source:23)
                                                                                          at android.os.Handler.handleCallback(Handler.java:789)
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                                          at android.os.Looper.loop(Looper.java:164)
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:6809)
                                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                                          at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                                       Caused by: java.lang.RuntimeException: Failed to gain exclusive lock to the Firestore client's offline persistence. This generally means you are using Firestore from multiple processes in your app. Keep in mind that multi-process Android apps execute the code in your Application class in all processes, so you may need to avoid initializing Firestore in your Application class. If you are intentionally using Firestore from multiple processes, you can only enable offline persistence (i.e. call setPersistenceEnabled(true)) in one of them.
                                                                                          at com.google.android.gms.internal.zzeqn.start(Unknown Source:34)
                                                                                          at com.google.android.gms.internal.zzenf.zza(Unknown Source:54)
                                                                                          at com.google.android.gms.internal.zzenh.run(Unknown Source:8)
                                                                                          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
                                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                                                                                          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
                                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                                                          at com.google.android.gms.internal.zzeuu$zza.run(Unknown Source:7)
                                                                                          at java.lang.Thread.run(Thread.java:764)
                                                                                       Caused by: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): , while compiling: PRAGMA journal_mode
                                                                                          at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                                          at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                                                                                          at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:634)
                                                                                          at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:320)
                                                                                          at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:294)
                                                                                          at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
                                                                                          at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
                                                                                          at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
                                                                                          at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
                                                                                          at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
                                                                                          at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:833)
                                                                                          at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:818)
                                                                                          at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:721)
                                                                                          at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:740)
                                                                                          at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:300)
                                                                                          at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:254)
                                                                                          at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:194)
                                                                                          at com.google.android.gms.internal.zzeqn.start(Unknown Source:19)
                                                                                          at com.google.android.gms.internal.zzenf.zza(Unknown Source:54) 
                                                                                          at com.google.android.gms.internal.zzenh.run(Unknown Source:8) 
                                                                                          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457) 
                                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
                                                                                          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) 
                                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
                                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
                                                                                          at com.google.android.gms.internal.zzeuu$zza.run(Unknown Source:7) 
                                                                                          at java.lang.Thread.run(Thread.java:764) 
  </code></pre>
  
  <p>I have searched a lot but have not been quite able to find the issue. How do I fix this?</p>