My activity's onResume() reads off some "extras" data from the Intent that started it and updates the UI accordingly.
I'd like to add error handling: if the data in the Intent is missing/corrupted, the activity displays a Toast and finishes.
Can I simply call finish() in the onResume() method? I'm worried about some unexpected things given that both are related to the life cycle.
If there are other better ways, I'm interested in these too, but the above seems simplest.
Thanks!
It is safe for an Activity to self-terminate by calling finish() at any time without it having any detrimental effect.
Obviously you have to be sure you have saved any required settings/data before calling finish() but that goes without saying and is entirely your responsibility based on your Activity design.
Calling finish()
in onResume()
should be fine. But why do you do the error handling in onResume()
and not in onCreate()
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With