我在应用程序中有多个对话框片段。当屏幕变得更暗时,一次又一次显示对话框,就像出现对话框时一样。如果我从任务管理器中删除应用程序并再次打开,则解决了Probelem问题。有趣的是,在Android 7.0+问题上没有出现问题。我检查了日志,一切正常,代码正在执行。以下是其中一个对话框片段:
/**
* Created by yusufabd on 7/9/2017.
*/
public class DialogBankBranch extends DialogFragment implements View.OnClickListener, BankBranchView{
@BindView(R.id.text_bank_title)
TextView tvTitle;
@BindView(R.id.text_value_manager)
TextView tvManager;
@BindView(R.id.text_value_phone)
TextView tvPhone;
@BindView(R.id.text_value_email)
TextView tvEmail;
@BindView(R.id.text_value_info)
TextView tvInfo;
private static final String ARG_BANK = "arg_bank";
private BankDatum bank;
private BankBranchPresenter presenter;
public static void showDialog(Activity activity, String title, String msg){
DialogBankBranch dialog = new DialogBankBranch();
Bundle bundle = new Bundle();
dialog.setArguments(bundle);
make(activity, dialog);
}
public static void showDialog(Activity activity, BankDatum bank){
DialogBankBranch dialog = new DialogBankBranch();
Bundle bundle = new Bundle();
bundle.putParcelable(ARG_BANK, bank);
dialog.setArguments(bundle);
make(activity, dialog);
}
protected static void make(Activity activity, DialogFragment dialogFragment){
if (activity != null){
android.support.v4.app.FragmentTransaction transaction = ((FragmentActivity) activity).getSupportFragmentManager().beginTransaction();
dialogFragment.show(transaction, "");
}
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
dialog.setCancelable(false);
return dialog;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null){
bank = getArguments().getParcelable(ARG_BANK);
}
if (bank == null){
showError(R.string.error_bank_data_not_found);
getDialog().dismiss();
return;
}
presenter = new BankBranchPresenter(this, bank);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_map, container);
ButterKnife.bind(this, view);
tvTitle.setText(bank.getBranch());
tvManager.setText(bank.getManager());
tvPhone.setText(bank.getPhone());
tvEmail.setText(bank.getEmail());
tvEmail.setOnClickListener(this);
tvPhone.setOnClickListener(this);
Spanned info = Html.fromHtml(LanguageUtil.isUzbek() ? bank.getInfoUzb() : bank.getInfo());
tvInfo.setText(info);
return view;
}
@Override
public void onClick(View v) {
presenter.onClick(v.getId());
}
@Override
public void start(Intent intent) {
startActivity(intent);
}
public void showError(String msg) {
MyToast.show(msg);
}
public void showError(int msgId) {
MyToast.show(msgId);
}
}
这可能是什么原因?
答案 0 :(得分:0)
因为您正在使用fragmentManager创建dialogFragment,而您应该使用fragmentChildManager来嵌套片段