I want to utilize `Activity#addOnNewIntentListener...
# compose
j
I want to utilize
Activity#addOnNewIntentListener()
within Compose. It works fine in general. However it's registered too later after a process death occurred. Code in 🧵
My Code looks like this:
Copy code
override fun onCreate(savedInstanceState: Bundle?) {
    setContent {
        addOnNewIntentListener {
            ...
        }
    }
}
I want to process shared text. Problem:
onNewIntent()
from the Activity is called before the lambda of
setContent
is invoked after a process death occured and the user re-starts the app with sharing a text. • When the App is not restored this works fine because the data is in the normal App intent • When the App is running already this works because the intent listener is called normally
a
For cases like these where there's a strong ordering requirement and you're interacting with things closer to the system (like listening for new intents) you might be safer setting those up outside
setContent
. Even when something like
addOnNewIntentListener
is directly in the Composable scope (you'd usually want to use something like a
DisposableEffect
for adding or removing a listener), that can be too late as you've discovered. A similar thing would apply for anything along the lines of "call this before
onCreate
returns." Everything inside
setContent
will be called at some later point in time, as determined by Compose internals.
221 Views