I use a ProgressDialog in the thread. In the onButtonClick the thread is started, but when I touch anywhere on the screen the ProgressDialog<
Add this to your dialog:
yourDialog.setCanceledOnTouchOutside(false);
In this way you can touch screen and the Dialog will be not canceled.
EDIT
If you are using DialogFragment, then you must use the following code snippet before calling show(FragmentManager mng, String tag):
More info here.
dialogFragment.setCancelable(false);
EDIT 2
Be careful with ProgressDialog , because with Android Oreo (v8.0) it is now deprecated.