title: Android: Set a Time out for AsyncTask
body: <p>We know AsyncTask is used in Android for short time background process. Generally we using for WepApi parsing, In Some time "<strong><code>doInBackground()</code></strong>" execute for a long time for getting the response.</p>
  
  <p>Suppose at the time of execution of <strong><code>doInBackground</code></strong> if our internet is gone , the progress bar still working to getting the result.</p>
  
  <p>So my question is can we set a TIMEOUT  for the <strong><code>doInBackground</code></strong> execution like if it execute more than 2 min stop the <strong><code>doInBackground</code></strong> execution and call <strong><code>onPostExecute</code></strong>.</p>
  
  <p>i tryed this method in <strong><code>doInBackground</code></strong> call</p>
  
  <pre><code> protected Void doInBackground(String... params) {
          // TODO Auto-generated method stub
          //String request = String.format(params[0], "12");
          Log.e("Tag " ,"Pasing Start");
          replay= getResponseByParsing(URL);
          new Handler().postDelayed(new Runnable() {
  
              @Override
              public void run() {
  
                 Toast.makeText(MainActivity.this,"Checking async task",Toast.LENGTH_LONG).show();
              }
          }, 20000);
  </code></pre>
  
  <p>but the application going to forcefully close</p>
  
  <p>what will be the good solution for set a TIMEOUT <strong><code>doInBackground</code></strong> exection</p>
  
  <p>Thanks in advance</p>