From: Damyan Ivanov Date: Wed, 21 Apr 2021 20:03:06 +0000 (+0300) Subject: convert DatabaseInitTask to a lightweight thread X-Git-Tag: v0.18.0~62 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=3eb8ad724a5280845bc3320b52136e3ea699bcf1;p=mobile-ledger.git convert DatabaseInitTask to a lightweight thread looks much cleaner --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java index 495a328f..7ab3e279 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java @@ -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 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 { + 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); } } }