diff --git a/activityresult/src/main/java/com/hss01248/activityresult/GoOutOfAppForResultFragment.java b/activityresult/src/main/java/com/hss01248/activityresult/GoOutOfAppForResultFragment.java index e6214de..6d04bd4 100644 --- a/activityresult/src/main/java/com/hss01248/activityresult/GoOutOfAppForResultFragment.java +++ b/activityresult/src/main/java/com/hss01248/activityresult/GoOutOfAppForResultFragment.java @@ -43,25 +43,23 @@ public void onStop() { startWaitingResult = true; } - @Override - public void onStart() { - super.onStart(); - if(startWaitingResult){ - onStartOfResultBack(); - startWaitingResult = false; - } - } - + /** + * 如果真有,那么比onStart()先执行 + * @param requestCode + * @param resultCode + * @param data + */ @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if(startWaitingResult){ consumed = true; - listener.onActivityResult(requestCode,resultCode,data); if (StartActivityUtil.debugable) { Log.i("onActivityResult", "req:" + requestCode + ",result:" + resultCode + ",data:" + data); } + onStartOfResultBack(requestCode,resultCode,data); + //不会在回来时回调,而是一跳出去就回调,resultcode是cancel,所以这个方法不能用 } //consumed = true; @@ -70,8 +68,17 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d } - protected void onStartOfResultBack() { - listener.onActivityResult(requestCode,66,null); + @Override + public void onStart() { + super.onStart(); + if(startWaitingResult && !consumed){ + onStartOfResultBack(requestCode,66,null); + startWaitingResult = false; + } + } + + protected void onStartOfResultBack(int requestCode, int resultCode, @Nullable Intent data) { + listener.onActivityResult(requestCode,resultCode,data); if (StartActivityUtil.debugable) { Log.i("onActivityResult2", "req:" + requestCode + ",result:onStartOfResultBack,data:null" ); }