Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finish sub activities programmatically

I have an activity that launches another activity with startActivityForResult method. I would like to terminate the called one programmatically but I don't know how to do this since in onActivityResult() method I have no information about the called activity and I cannot call finish() on it. How can I achieve this?

Thanks

like image 267
Matroska Avatar asked Dec 02 '25 10:12

Matroska


2 Answers

The launched Activity can finish self:

setResult(RESULT_OK);
finish();
like image 180
yanchenko Avatar answered Dec 05 '25 00:12

yanchenko


Try finishActivity(requestCode). According to the documentation it lets you finish an activity previously started with startActivityForResult. And if there are multiple such activities with the same request code, all will be finished.

Note: I haven't actually tried this myself, but that's what the documentation says! Experiment with that, see if it does what you want.

like image 32
Steve Haley Avatar answered Dec 04 '25 23:12

Steve Haley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!