0

showrag() 및 add() 메서드를 사용하여 시도한 대화 상자 조각을 작업 중에 표시하고 있습니다. 코드가 나는 위의 코드에서 때때로 IllegalStateException이 오류가getSupportFragmentManager가 호환 라이브러리에서 실패했습니다.

HelpDialogFragment hdf = HelpDialogFragment.newInstance(); 
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 
ft.add(hdf, "dialog"); 
ft.commit(); #crash here 

아래에 주어진, 충돌 로그는 더

java.lang.IllegalStateException: Activity has been destroyed 
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1329) 
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:548) 
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:532) 
at com.delight.activities.HomeActivity.showHelp(HomeActivity.java:311) 

라인 아래에 주어진다. HomeActivity.java의 311은 위의 코드에서 언급 한 ft.commit()입니다. 필자의 활동은 FragmentActivity를 호환성 라이브러리 (날짜로 업데이트 됨)에서 확장합니다. show() 메서드를 사용하면 같은 충돌이 발생합니다.

HelpDialogFragment hdf = HelpDialogFragment.newInstance(); 
hdf.show(getSupportFragmentManager(), "dialog"); #same crash here 

그래서 내가 getSupportFragmentManager() 나에게 문제를 일으키는 결론에 도달, 내가 이해하지 못하는 것은 코드의 어떤 부분에서 내가 늘어나는만큼, 파괴 된 활동을 사용하고 있다는 것입니다 getSupportFragmentManager() 님이 나와있는 활동에 대한 관리자를 보내 주어야한다고 이해하십시오.

이 문제를 해결하는 데 도움이 필요합니다.

+0

활동 코드를 게시 할 수 있습니까? – biegleux

+0

'Activity'의'onCreate()'에서 첫 문장으로'super.onCreate (savedInstanceState);를 호출 했나요? – biegleux

+0

네, 전화 했어요. –

답변

0

대화 상자 단편 U를 보려면 dialogfrag.show (Fmanager, tag) 만 호출하면됩니다. 그 그것을 할 DialogFragment를 확장 작동하지 않을 경우 거래를 통해 추가 예외

0

사용 getFragmentManager 대신에서 getSupportFragmentManager

dialog.show(getFragmentManager(), "submitting"); // The second parameter doesn't really matter. 

에게 제공합니다. 핵심은 지원 라이브러리를 사용하는 대신 대화 상자를 작성할 때 활동을 사용하는 것입니다.

dialog = new AlertDialogFragment(title, message); 
dialog.show(getFragmentManager(), "submitting"); 

AlertDialogFragment :

public class AlertDialogFragment extends DialogFragment { 

     static final String TAG_TITLE = "title"; 
     static final String TAG_MSG = "message"; 

     public AlertDialogFragment(){ 

     } 

     public AlertDialogFragment(String title, String message) { 
      Bundle b = new Bundle(); 
      b.putString(TAG_TITLE, title); 
      b.putString(TAG_MSG, message); 

      setArguments(b); 
     } 

     public AlertDialogFragment newInstance(String title, String message) { 
      AlertDialogFragment frag = new AlertDialogFragment(); 
      Bundle b = new Bundle(); 
      b.putString(TAG_TITLE, title); 
      b.putString(TAG_MSG, message); 

      frag.setArguments(b); 
      return frag; 
     } 

     public Dialog onCreateDialog(Bundle savedInstanceState) { 
      String title = getArguments().getString(TAG_TITLE); 
      String message = getArguments().getString(TAG_MSG); 
       // Use getActivity()! 
      return new AlertDialog.Builder(getActivity()).setTitle(title) 
        .setMessage(message) 
        .setNegativeButton("Dismiss", new OnClickListener() { 

         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          dismiss(); 
         } 
        }) 
        .setOnCancelListener(new OnCancelListener() { 

         @Override 
         public void onCancel(DialogInterface dialog) { 
          Log.d(TAG, "Dialog cancel"); 
         } 
        }).create(); 
     } 

     @Override 
     public void onCancel(DialogInterface dialog) { 
      Log.d(TAG, "Cancel Dialog"); 
      super.onCancel(dialog); 
     } 

     @Override 
     public void onDismiss(DialogInterface dialog) { 
      Log.d(TAG, "Dismiss Dialog"); 
      super.onDismiss(dialog); 
     } 
    } 

} 
+0

은 액티비티에서 getFragmentManager()를 사용할 수 없으며 조각에서만 사용할 수 있다고 생각합니다. –

+0

@YashwanthKumar (표준)'Activity'에서 (지원)'FragmentActivity'와'getFragmentManager()'에서'getSupportFragmentManager()'를 사용합니다. –

0

클래스는 FragmentActivity없는 활동을 확장해야합니다. 이 문제가 해결되었습니다