onActivityResult() 和onResume()的调用顺序问题

今天在做记事本开发的时候遇到遇到类似的问题,虽然打log能知道先后顺序,但是无法知道原因,于是百度了一下,发现一个问题,国内的网站上都是一帮等着吃闲饭的人。

于是借助了stackoverflow

得到如下的回答:

protected void onActivityResult (int  requestCode, int resultCode, Intent  data)

Since: API Level 1 Called when an  activity you launched exits, giving  you the requestCode you started it  with, the resultCode it returned, and  any additional data from it. The  resultCode will be RESULT_CANCELED if  the activity explicitly returned that,  didn't return any result, or crashed  during its operation. You will receive  this call immediately before  onResume() when your activity is  re-starting.

翻译过来如下:

protected void onActivityResult (int  requestCode, int resultCode, Intent  data)

当你调用完一个存在的activity之后,onActivityResult将会返回以下数据:你调用时发出的requestCode、被调用activity的结果标志resultCode(如RESULT_OK)和其他的额外数据。我们期望的都是得到RESULT_OK,表示调用成功,但是当被调用activity什么也没返回,或者调用过程中发生崩溃时,resultCode的值会为RESULT_CANCELED,重新回到调用activity时会马上执行onActivityResult方法,然后才是**onResume()**方法。

由此可见onActivityResult()发生在onResume()之前