Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onActivityResult gets called before onDestroy

Inside MainActivity.java I make the following call:

Intent activity = new Intent(this, CameraDetectionActivity.class);
startActivityForResult(activity, request);

And at some point inside CameraDetectionActivity I run the following 2 lines (all happens in the GUI thread):

setResult(Activity.RESULT_OK);
finish();

I would expect onDestroy to get called before onActivityResult in MainActivity but they are called in the opposite order. Any idea why this is happening?

like image 578
galbarm Avatar asked Jun 26 '11 15:06

galbarm


1 Answers

onDestroy is called at some point later, and that may be arbitrarily long. We want to resume the next activity as quickly as possible so the UI is in there, and then take care of stopping and destroying previous activities only once the UI has switched.

like image 186
hackbod Avatar answered Oct 16 '22 08:10

hackbod