Q: activity to fragment method calling in a thread with progressbar I am using this code, everything are working fine, but progressbar is not showing. I want to block my ui during the method implementation and want to show progressbar. I want to get behaviour like progressDialog.
Here is my method 
public void effct(int effectNo) {
        final int finalEffectNO = effectNo;
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
                WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
        progressLayout.setVisibility(View.VISIBLE);
        progressLayoutLinear.setVisibility(View.VISIBLE);

        Thread thread = new Thread(){
            @Override
            public void run() {

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        imageViewFragment.applyEffect(finalEffectNO);
                        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
                        progressLayout.setVisibility(View.GONE);
                        progressLayoutLinear.setVisibility(View.GONE);

                    }
                });
            }
        };
        thread.start();
    }

My xml code for progressLayout
<LinearLayout
            android:id="@+id/progressBarLinearLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark"
            android:gravity="center"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:padding="12dp"
            android:visibility="gone"
            android:orientation="horizontal">

            <ProgressBar
                android:id="@+id/progressBar"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_marginRight="10dp"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Loading"
                android:textColor="#FFFFFF"
                android:textStyle="bold"
                android:textSize="18sp"/>

        </LinearLayout>


A: For above your requirement you must use ProgressDialog for same, here is an example
Example

A: Try using an AsyncTask instead of Thread, something like this :
   new AsyncTask<Void, Void, Void>() {
        @Override
        protected void onPreExecute() {
            progressLayoutLinear.setVisibility(View.VISIBLE);
        }

        @Override
        protected Void doInBackground(final Void ... params ) {

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    imageViewFragment.applyEffect(finalEffectNO);
                    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
                }
            });

            return null;
        }

        @Override
        protected void onPostExecute( final Void result ) {
            progressLayoutLinear.setVisibility(View.GONE);


        }
    }.execute();

Hope this helps

A: There's a few ways to solve your problem - check this video for more information. The most basic approach might be an AsyncTask, which could look like this:
public class DummyAsyncTask extends AsyncTask<Void, Void, Void> {
  private final Window window;
  private final ProgressBar progressBar;

  public DummyAsyncTask(Window window, ProgressBar progressBar) {
    this.window = window;
    this.progressBar = progressBar;
  }

  @Override protected void onPreExecute() {
    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
    progressBar.setVisibility(View.VISIBLE);
  }

  @Override protected Void doInBackground(Void... voids) {
    // Do the heavy lifting.
  }

  @Override protected void onPostExecute(Void aVoid) {
    window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
    progressBar.setVisibility(View.GONE);
  }
}

You execute it by running new DummyAsyncTask(/* params */).execute();. 
Do note that AsyncTask does not adhere to the lifecycle and holding a reference to a Context aware instance is just asking for trouble. A safer alternative might be using LiveData:
public void effect(int effectNo) {
  // Show progress and disable user interaction here.

  final ListData<Content> data = model.applyEffect(effectNo);
  data.observe(this, (Observer<Content>) c -> {
    // Apply results, hide progress & enable user interaction.
  });
}

Given the above, you should be careful how you handle showing & hiding progress, so you don't accidentally disable user interaction forever.
