Jetpack Compose Lauch Activity and Receive Result (Place Autocomplete example)

@Composablefun test() {    val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->        val data: Intent? = result.data        when(result.resultCode) {            Activity.RESULT_OK -> {                data?.let {                    val place = Autocomplete.getPlaceFromIntent(data)                    Timber.d("place=${place.name}")                }            }            AutocompleteActivity.RESULT_ERROR -> {                // TODO: Handle the error.                data?.let {                    val status = Autocomplete.getStatusFromIntent(data)                    Timber.e("error=${status.statusMessage}")                }            }            Activity.RESULT_CANCELED -> {                // The user canceled the operation.            }        }    }    fun launchAutocomplete() {        val fields = listOf(GooglePlace.Field.ID, GooglePlace.Field.NAME)        val intent = Autocomplete.IntentBuilder(AutocompleteActivityMode.OVERLAY, fields)            .build(context)        launcher.launch(intent)    }}

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.