Maybe a silly question, but curious to get thought...
# compose-android
c
Maybe a silly question, but curious to get thoughts. I'm working on an android only app and need to do some event based on a hardware (keycode) event. It seems like I can do it on the activity level (i.e.
override fun onKeyDown
) or I can do it in compose (
onKeyEvent
modifier on the Compose screen) Anyone feel strongly on what route to take?
a
Prefer handling it in Compose: The Activity-level is not going to scale very well if that Activity is responsible for displaying many different parts of your app or all of your app. Handling it in Compose allows any logic to be localized to a specific part of your UI
j
What would prevent this from scaling by placing the logic in the Activity? Unless the key event behaviour needs to happen only when a specific screen/view is on screen, it would be simpler to have a global listen vs registering it on every Composable screen/nav route.
1
s
Well if it truly is a global event and should be set no matter which screen you are in, you can add the handler at the top level composable too, before any NavHost etc. Don't see the appeal of polluting your activity with something like this.