2014-12-31 4 views
1

단편에서 startActivityForResult()가 호출 될 때 onActivityResult()가 단편에서 호출되지 않는 이유에 대한 많은 게시물이 있습니다. 하지만 제 경우는 다릅니다.새 활동이 단편에서 시작된 경우 기본 활동에서 onActivityResult()가 호출되지 않음

내 활동 A에는 결과에 대한 활동 B를 시작하는 단편 F가 있습니다. 프래그먼트는 결과를 아무 문제없이 여기에서받습니다. 문제는 활동 A가 다시 시작될 때 onResume() 중에 호출되는 AsynTask를 사용하여 전체보기를 비동기 적으로 작성한다는 점입니다. 그 결과, 내 조각 F 내 조각에서 활동 A.

에 의해 덮여있다,이 같은 활동을 시작합니다

startActivityForResult(intent, NewElementFragment.CODE_IMAGE_PATH); 

그래서 내가 걱정, 나는 onResume()가 호출 될 것을 모른다, 생각 onActivityResult() 이후에는 onActivityResult()에서 onResume() 중에 뷰가 생성되지 않도록해야합니다.

는이 같은 내가 onActivityResult를 (시 false로 설정 부울) 생성 :

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    //put the NewElementFragment back on top 
    if (requestCode == NewElementFragment.CODE_IMAGE_PATH){ 
     //we set loadinfo to false so that the activity view won't get built 
     this.loadInfo = false; 
     Log.d("MainActivity","the loadInfo boolean was set to false"); 
    } 
    //Do default action on result (nothing) so that the result is passed on the the fragments 
    super.onActivityResult(requestCode, resultCode, data); 
} 

을하지만 분명히하여 onActivityResult()가 내 활동 A (트리거 적이 있기 때문에 작동하지 않았다 심지어 비록 I 그것이 나의 조각에서 완전하게 유발되기 전에 말했다). 내가 활성 단편이 있다면

그래서 결국 나는 이력서에 체크인하고있는 경우는 예, 뷰 생성과 같은 중지 :

protected void onResume(){ 
    super.onResume(); 
    /* 
    * We check if there is a fragment built that should be visible. If yes, we don't build the view 
    */ 
    NewElementFragment f = (NewElementFragment) getFragmentManager().findFragmentByTag(TAG_NEW_ELEMENT_FRAGMENT); 
    if (f!=null){ 
     loadInfo = false; 
    } 
    //We call the GetProductDetailTask 
    if (loadInfo) new GetProductDetailTask(pId).execute();  
} 

그것은 작동하지만 나는 그것이 매우 추한 찾을 수 있습니다. 누군가가 내 활동 A에서 onActivityResult()가 호출되지 않는 이유를 말할 수 있습니까?

누군가가 내 조각을 다시 시작할 때 내 조각으로 덮지 않았는지 확인하는 더 좋은 해결책이 있습니까?

감사합니다.

답변

0

귀하의 호스팅 활동은 일부 인터페이스를 구현해야하며 귀하의 조각에서 호출해야합니다. 이 인터페이스 구현에서는 startActivityForResult()을 통해 다른 활동을 호출 할 수 있습니다. 이 경우 onActivityResult() 처리가 완료됩니다.