FinishAppListener finishAppListener = new FinishAppListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialogWhich.Y) {
try{
dialog.dismiss();
System.exit(0);////not use finish(); because onDetach bug
}catch (Exception e){
e.printStackTrace();
}
}
}
};
Utils.showAlertDialogYorN(this, getResources().getString(R.string.askExistApp), finishAppListener);
}
http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed
在每個fragmnet加上
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
不然的話你就會看到
Activity has been destroyed 的錯誤
沒有留言:
張貼留言