How to hide progress bar after 10 seconds in Android?
<p>I am working on <code>Android</code>. I want to show the progress bar only for 10 seconds after the connection to <code>www.google.com</code> is success. Here is my code. Any help is appreciated.</p>

<p><strong>MainActivity.java</strong></p>

<pre><code>import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {
    Button button1;
    Public ProgressBar mProgress;
    progressCheck obj = new progressCheck(mProgress);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Button fab = (Button) findViewById(R.id.button1);
        mProgress =(ProgressBar) findViewById(R.id.progressBar);
        mProgress.setVisibility(View.GONE);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    obj.execute();
            }
        });


    }
</code></pre>

<p><strong>ProgressCheck.java extends AsyncTask</strong></p>

<pre><code>   import android.os.AsyncTask;
import android.view.View;
import android.widget.ProgressBar;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;

public class progressCheck  extends AsyncTask&lt;String, String, String&gt; {
    ProgressBar mProgressBar;

    public progressCheck(ProgressBar p){
        this.mProgressBar = p;
    }


    @Override
    protected String doInBackground(String... params) {

        Document doc = null;
        String url = "https://www.google.com.pk/";
        try {
            doc = Jsoup.connect(url).timeout(20 * 1000).get();
            Thread.sleep(10000);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        mProgressBar.setVisibility(View.GONE);

    }


    @Override
    protected void onPreExecute() {
        mProgressBar.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onProgressUpdate(String... text) {


    }

}
</code></pre>

<p><strong>Content_main.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.namal.circularprogressbar2.MainActivity"
    tools:showIn="@layout/activity_main"&gt;

    &lt;ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_marginTop="36dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:indeterminate="false" /&gt;

    &lt;Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start"
        android:id="@+id/button1"
        android:layout_below="@+id/progressBar"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="72dp" /&gt;


&lt;/RelativeLayout&gt;
</code></pre>