From f833689961faff35d3d0838bc229b0e90c2167f4 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 7 Oct 2024 18:58:17 +0200 Subject: [PATCH] prevent ANR by moving Binder call off main thread --- .../src/main/kotlin/deckers/thibault/aves/MainActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt b/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt index 9756254ad..837b7ead9 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/MainActivity.kt @@ -437,7 +437,7 @@ open class MainActivity : FlutterFragmentActivity() { val pickedUris = call.argument>("uris") try { if (!pickedUris.isNullOrEmpty()) { - val toUri = { uriString: String -> AppAdapterHandler.getShareableUri(this, Uri.parse(uriString)) } + val toUri = { uriString: String -> AppAdapterHandler.getShareableUri(this@MainActivity, Uri.parse(uriString)) } val intent = Intent().apply { val firstUri = toUri(pickedUris.first()) if (pickedUris.size == 1) { @@ -455,7 +455,8 @@ open class MainActivity : FlutterFragmentActivity() { } else { setResult(RESULT_CANCELED) } - finish() + // move code triggering `Binder` call off the main thread + defaultScope.launch { finish() } } catch (e: Exception) { if (e is TransactionTooLargeException || e.cause is TransactionTooLargeException) { result.error("submitPickedItems-large", "transaction too large with ${pickedUris?.size} URIs", e)