From 05857ad7d85ba73b3f67571f89e12f114874bc98 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 12 Mar 2018 14:31:06 +0100 Subject: Check for activity termination before updating UI elements --- app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt | 4 ++++ app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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 44f3210..ff5b930 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt @@ -41,6 +41,10 @@ abstract class BaseActivity : AppCompatActivity() { .show() } + fun runOnUiThread(action: () -> Unit) { + if (!isFinishing && !isDestroyed) super.runOnUiThread(action) + } + protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() protected fun showProgressDialog(@StringRes msg: Int): ProgressDialog = ProgressDialog.show(this, null, getString(msg), true, false) diff --git a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt index 351305c..4206f7f 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt @@ -139,7 +139,7 @@ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRef text_network_disallowed_applications.setText(cfg.disallowedApplications) } - private fun writeNodeList(nodeList: List) = runOnUiThread { + private fun writeNodeList(nodeList: List) { nodeListAdapter?.setElements(nodeList) node_list_placeholder.visibility = View.GONE list_wrapper.isRefreshing = false -- cgit v1.2.3