]> git.ktnx.net Git - mobile-ledger.git/commitdiff
convert DatabaseInitTask to a lightweight thread
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 21 Apr 2021 20:03:06 +0000 (23:03 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 21 Apr 2021 20:03:06 +0000 (23:03 +0300)
looks much cleaner

app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java

index 495a328f9a2aef6c30c7231db3333e6c3462806f..7ab3e27937214239f06667aaab7f49b6de8ba5e5 100644 (file)
@@ -18,7 +18,6 @@
 package net.ktnx.mobileledger.ui.activity;
 
 import android.content.Intent;
-import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Handler;
 
@@ -51,9 +50,9 @@ public class SplashActivity extends CrashReportingActivity {
 
         startupTime = System.currentTimeMillis();
 
-        AsyncTask<Void, Void, Void> dbInitTask = new DatabaseInitTask();
+        DatabaseInitThread dbInitThread = new DatabaseInitThread();
         Logger.debug("splash", "starting dbInit task");
-        dbInitTask.execute();
+        dbInitThread.start();
     }
     @Override
     protected void onPause() {
@@ -96,18 +95,14 @@ public class SplashActivity extends CrashReportingActivity {
             finish();
         }
     }
-    private static class DatabaseInitTask extends AsyncTask<Void, Void, Void> {
+    private static class DatabaseInitThread extends Thread {
         @Override
-        protected Void doInBackground(Void... voids) {
-            long ignored = DB.get().getProfileDAO().getProfileCountSync();
+        public void run() {
+            long ignored = DB.get()
+                             .getProfileDAO()
+                             .getProfileCountSync();
 
-            return null;
-        }
-        @Override
-        protected void onPostExecute(Void aVoid) {
-            Logger.debug("splash", "DatabaseInitTask::onPostExecute()");
-            super.onPostExecute(aVoid);
-            MobileLedgerDatabase.initComplete.setValue(true);
+            MobileLedgerDatabase.initComplete.postValue(true);
         }
     }
 }