Can onActivityResult()
theoretically be called before onCreate
? I know it can be called before onResume()
, but let's consider this extreme case:
What happens now? Does activity A get re-created before receiving the result, or does it receive the result before onCreate()
? Is this guaranteed to be in the same order each time?
You will commonly see this if you are opening an app to scan a barcode or take a photo or video. The Activity
you launch to do that requires a lot of resources so Android kills the OS process hosting your app.
When the Activity
you launched wants to return the result to your app, the following occurs:
Application
instance (or your app's custom one) and calls onCreate()
on that Activity
that will get the result (the one that called startActivityForResult()
) onCreate()
on the new Activity
. The Bundle
passed to onCreate()
in this case is the Bundle
most recently used to the save the Activity
instance state (from onSaveInstanceState()
).onStart()
on the new Activity
onActivityResult()
on the new Activity
onResume()
on the new Activity
Those case Use
registerForActivityResult()
Activity Result APIs decouple the result callback from the place in your code where you launch the other activity. As the result callback needs to be available when your process and activity are recreated, the callback must be unconditionally registered every time your activity is created, even if the logic of launching the other activity only happens based on user input or other business logic
more details refer Getting a result from an activity
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.