問題回顧:
在Android8.0手機(jī)上不能直接安裝Apk,需要權(quán)限申請(qǐng),回調(diào)后執(zhí)行onActivityResult()方法,并彈出對(duì)應(yīng)的dialog,這時(shí)需要判斷當(dāng)前Activity是否處于resume狀態(tài),通過變量來控制,但結(jié)果是這個(gè)dialog并不會(huì)彈出。
問題本質(zhì)
Activity跳轉(zhuǎn)到系統(tǒng)應(yīng)用后回調(diào)onActivityResult() 先執(zhí)行還是onResume()先執(zhí)行?
查看源碼
/**
* 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.
*
* <p>This method is never invoked if your activity sets
* {@link android.R.styleable#AndroidManifestActivity_noHistory noHistory} to
* <code>true</code>.
*
* @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)
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
onActivityResult()注釋中有這么一句話:
You will receive this call immediately before onResume() when your activity is re-starting.
(意思是說當(dāng)你的Activity重新啟動(dòng)時(shí) onActivityResult() 會(huì)在onResume()之前執(zhí)行)
很顯然,如果你的Activity 調(diào)用了
startActivityForResult()方法啟動(dòng),回調(diào)之后會(huì)先執(zhí)行onActivityResult(),然后執(zhí)行onResume()