I have solved the issue.I just implemented a interface in dialog B.Checks and initialize interface in onCreate method in dialog A whether the hosting dialog is activity /dialog.
Here is the code 
Dialog DialogTwo as A :
public class DialogTwo extends DialogFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        if(!(getActivity() instanceof SelectedItemListener)) {
            callback = (SelectedItemListener) getTargetFragment();
        }
    } catch (Exception e) {
        throw new ClassCastException("Calling Fragment must implement SelectedItemListener");
    }
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.AlertDialogCustom));
    builder.setTitle(R.string.select_color)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    if (getActivity() instanceof SelectedItemListener) {
                            ((NewExerciseActivity) getActivity()).manageSelectedItem();
                    }else {
                        callback.manageSelectedItem();
                    }
                }
            })
            .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                }
            });
    return builder.create();
   }
}
Call from Dialog B :
 private void showDialog() {
    FragmentActivity activity = (FragmentActivity) getActivity();
    FragmentManager fm = activity.getSupportFragmentManager();
    DialogTwo dialogTwo = new DialogTwo();
    dialogTwo.setTargetFragment(this,0);
    dialogTwo.show(fm, "dialogTwo");
}
@Override
public void manageSelectedItem() {
       //do something
}