From 3eb8ad724a5280845bc3320b52136e3ea699bcf1 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Wed, 21 Apr 2021 23:03:06 +0300 Subject: [PATCH] convert DatabaseInitTask to a lightweight thread looks much cleaner --- .../ui/activity/SplashActivity.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) 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); } } } -- 2.39.5