From 1ac3d386edca75fc8870f2c6b4a19cd58c333289 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 23 Apr 2018 12:34:43 +0200 Subject: Do not update UI while an activity is not on screen --- .../org/pacien/tincapp/activities/BaseActivity.kt | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'app/src/main') diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt index cc79600..bad2f8b 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt @@ -20,6 +20,8 @@ import org.pacien.tincapp.context.CrashRecorder * @author pacien */ abstract class BaseActivity : AppCompatActivity() { + private var active = false + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.base) @@ -31,6 +33,26 @@ abstract class BaseActivity : AppCompatActivity() { return true } + override fun onStart() { + super.onStart() + active = true + } + + override fun onResume() { + super.onResume() + active = true + } + + override fun onPause() { + active = false + super.onPause() + } + + override fun onStop() { + active = false + super.onStop() + } + fun aboutDialog(@Suppress("UNUSED_PARAMETER") i: MenuItem) { AlertDialog.Builder(this) .setTitle(BuildConfig.APPLICATION_ID) @@ -44,7 +66,7 @@ abstract class BaseActivity : AppCompatActivity() { } fun runOnUiThread(action: () -> Unit) { - if (!isFinishing && !isDestroyed) super.runOnUiThread(action) + if (active) super.runOnUiThread(action) } private fun handleRecentCrash() { -- cgit v1.2.3