android – Progress Dialog is not dismissing after the given delay any solution?-ThrowExceptions

Exception or error:
 btnUpdateEduInfo.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            progressDialog.show();
                                            new Handler().postDelayed(new Runnable() {
                                                public void run() {
                                                    progressDialog.dismiss();
                                                    //Toast.makeText(getContext(),"Something went wrong!",Toast.LENGTH_SHORT).show();
                                                }
                                            }, 1000);
        });

I want to show progress dialog when I save data in fire base and dismiss dialoq if data is not saved. I have used thread and handler but nothing works. any solution for this problem?

How to solve:

You dissmiss dialog in worker thread so being this problem.
Apply below solution

 btnUpdateEduInfo.setOnClickListener(new View.OnClickListener()

    {
        @Override
        public void onClick (View v){
        progressDialog.show();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                YourActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        progressDialog.dismiss();
                    }
                });

                //Toast.makeText(getContext(),"Something went wrong!",Toast.LENGTH_SHORT).show();
            }
        }, 1000);
    });

Leave a Reply

Your email address will not be published. Required fields are marked *