AlertDialog – proper way to build it. Now blink and flick opening Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of AlertDialog – proper way to build it. Now blink and flick opening without wasting too much if your time.

The question is published on by Tutorial Guruji team.

In my project I am using a simple AlertDialog to enter some information. My problem is that when I go to open this AlertDialog I have a flicker for a very short time which is not correct. I would like to know what I’m wrong and above all what should be the correct way to build it because I can’t find a solution around, if not that of changing objects. But I would really need the AlertDialog

    private void insertNameManually(String hint, int mType) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
    LayoutInflater inflater = this.getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.alert_dialog, null);
    EditText editText = dialogView.findViewById(;
    Button clearTextButton = dialogView.findViewById(;
    Button confirmButton = dialogView.findViewById(;
    confirmButton.setOnClickListener(v -> {

        name = editText.getText().toString();

        name = hint;
        new Handler().postDelayed(() -> {
            MyFragment.this.type = mType;
            Intent data = new Intent();
            data.putExtra("type", type);
            activity.setResult(Activity.RESULT_OK, data);
        }, 275);


    clearTextButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

    AlertDialog alertDialog = dialogBuilder.create();;


Solution: You can try by adding flag to your alert dialog, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;

You can try by switching to a DialogFragment can help to remove the flicker.

Tip: Just want add here by looking at your code instead of,

  AlertDialog alertDialog = dialogBuilder.create();;

You can do this way, will create and show the alert dialog.;
We are here to answer your question about AlertDialog – proper way to build it. Now blink and flick opening - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji