AlertDialog - я создаю утечку памяти, не вызывая .hide ()? - PullRequest
0 голосов
/ 28 сентября 2019

Вот мой fragment, который использует AlertDialog -

public class PhoneStateAndAgeVerificationFragment extends AbstractFragment {
@BindView(R.id.frag_verification_phone_checkbox_age)
CheckBox checkBoxAge;
private AlertDialog.Builder mBuilder;
private Dialog mDialog;


public static Fragment newInstance() {
    return new PhoneStateAndAgeVerificationFragment();
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mBuilder = new AlertDialog.Builder(getActivity(), R.style.DialogTheme);
}

@OnCheckedChanged(R.id.frag_verification_phone_checkbox_age)
void OnAgeCheckedChanged(CompoundButton button, boolean checked) {
    if (checked) {
        button.setTextColor(ContextCompat.getColor(button.getContext(), R.color.black));
    }
}

@OnClick(R.id.verification_button_got_it)
void onBtnGotItClicked(View view) {
    if (!checkBoxAge.isChecked()) {
        checkBoxAge.setTextColor(ContextCompat.getColor(checkBoxAge.getContext(), R.color.accent_red));
        return;
    }
    showDialog();
    if (getContext() instanceof VerificationPageListener) {
        ((VerificationPageListener) getContext()).onPageAgreed();
    }
}
@Override
protected int getLayoutResourceId() {
    return R.layout.layout_verification_phone_age;
}


private void showDialog(){
    if (mBuilder == null) {
        mBuilder = new AlertDialog.Builder(App.getAppContext());
    }
    mBuilder.setCancelable(false);
    mBuilder.setView(R.layout.custom_proggress_dialog);
    mDialog = mBuilder.create();
    mDialog.show();
}

}

Как вы можете видеть, я строю alert dialog и показываю егопользователь.Если пользователь нажал все необходимые кнопки, он затем переходит на следующий экран.Что меня беспокоит, так это то, что alert dialog создается и показывается, я создаю утечку памяти таким образом?если нет - по какой причине нет, и если да - что было бы хорошим решением для этого?

...