Skip to content

Commit

Permalink
prevent ANR by moving Binder call off main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Oct 7, 2024
1 parent 0f5d0a4 commit f833689
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ open class MainActivity : FlutterFragmentActivity() {
val pickedUris = call.argument<List<String>>("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) {
Expand All @@ -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)
Expand Down

0 comments on commit f833689

Please sign in to comment.