From e91536d17cacca8d7f564eea0f4eb4ff11142433 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 28 Aug 2024 20:54:58 -0400 Subject: [PATCH 1/2] Fix crash on autocomplete error --- .../com/example/placesdemo/PlaceAutocompleteActivity.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt index b12f823f..4242c6fb 100644 --- a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt +++ b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt @@ -129,7 +129,7 @@ class PlaceAutocompleteActivity : AppCompatActivity() { /** * Launches Autocomplete activity and handles result */ - private var autocompleteLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + private val autocompleteLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> when (result.resultCode) { AutocompleteActivity.RESULT_OK -> { @@ -141,8 +141,8 @@ class PlaceAutocompleteActivity : AppCompatActivity() { } } AutocompleteActivity.RESULT_ERROR -> { - val status = Autocomplete.getStatusFromIntent(intent) - binding.response.text = status.statusMessage + val status = Autocomplete.getStatusFromIntent(data) + binding.response.text = "Error: ${status.statusMessage}" } AutocompleteActivity.RESULT_CANCELED -> { // The user canceled the operation. @@ -287,4 +287,4 @@ class PlaceAutocompleteActivity : AppCompatActivity() { .setMessage(messageResId) .show() } -} \ No newline at end of file +} From a43f8f38287e1f060d639d9adf3bb14e979bf4be Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 28 Aug 2024 21:19:17 -0400 Subject: [PATCH 2/2] use correct intent --- .../java/com/example/placesdemo/PlaceAutocompleteActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt index 4242c6fb..07eff74c 100644 --- a/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt +++ b/demo-kotlin/app/src/main/java/com/example/placesdemo/PlaceAutocompleteActivity.kt @@ -141,7 +141,7 @@ class PlaceAutocompleteActivity : AppCompatActivity() { } } AutocompleteActivity.RESULT_ERROR -> { - val status = Autocomplete.getStatusFromIntent(data) + val status = Autocomplete.getStatusFromIntent(result.data) binding.response.text = "Error: ${status.statusMessage}" } AutocompleteActivity.RESULT_CANCELED -> {