A ——> startActivityForResult ——> B ——>setResult 不执行finish 方法 A是在B执行了setResult方法还是B被finish后执行onActivityResult方法?
A ——> startActivityForResult ——> B ——>setResult ——> finish 如果栈里面A和B中间还有activity A将不会在(B setResult和finish)后执行onActivityResult方法 而是在A startActivityForResult 后马上执行 参数resultCode为RESULT_CANCEL 该情况可能会出现在A与B不在同一栈的情况(如B的启动模式为单栈(详情))
正确调用顺序如下
A ——> startActivityForResult ——> B ——>setResult ——> finish ——> A——>onActivityResult ——>onRestart——>onStart——>onResume
原因Activity的onActivityResult方法注释如下
/**
* 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 <var>resultCode</var> will be
* {@link #RESULT_CANCELED} if the activity explicitly returned that,
* didn‘t return any result, or crashed during its operation.
*
* <p>You will receive this call immediately before onResume() when your
* activity is re-starting.
*
* @param requestCode The integer request code originally supplied to
* startActivityForResult(), allowing you to identify who this
* result came from.
* @param resultCode The integer result code returned by the child activity
* through its setResult().
* @param data An Intent, which can return result data to the caller
* (various data can be attached to Intent "extras").
*
* @see #startActivityForResult
* @see #createPendingResult
* @see #setResult(int)
*/
执行onActivityResult之前先执行onResume方法 经测试onStart方法在onActivityReult后面 onRestart应该一样
结论先执行onActivityResult在执行生命周期方法