title: Whenever I click the button it gives me last value result not current
body: <p>Whenever I execute data function it stores the correct value of QUERY  but when i get the JSON back. It gives me the result of last value  rather than giving me the result of new value. Something is wrong in function data or function async.  </p>
  
  <p>There is no error which that I give you my error log.The QUERY string holds the right value but result is of last string.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity{
          public static String QUERY = null;
          public static String DATA = null;
          SpeechRecognizer speechRecognizer;
          Intent speechIntent;
          TextView textView;
          Button button;
          TextView textView1;
  
          @RequiresApi(api = Build.VERSION_CODES.M)
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate (savedInstanceState);
              setContentView (R.layout.activity_main);
              textView = (TextView) findViewById (R.id.text);
              textView1 = (TextView) findViewById (R.id.text1);
  
              requestPermissions (new String[]{Manifest.permission.INTERNET, Manifest.permission.RECORD_AUDIO}, 10);
  
              speechRecognizer = SpeechRecognizer.createSpeechRecognizer (this);
              speechRecognizer.setRecognitionListener (new RecognitionListener () {
                  @Override
                  public void onReadyForSpeech(Bundle bundle) {
  
                  }
  
                  @Override
                  public void onBeginningOfSpeech() {
  
                  }
  
                  @Override
                  public void onRmsChanged(float v) {
  
                  }
  
                  @Override
                  public void onBufferReceived(byte[] bytes) {
  
                  }
  
                  @Override
                  public void onEndOfSpeech() {
  
                  }
  
                  @Override
                  public void onError(int i) {
  
                  }
  
                  @Override
                  public void onResults(Bundle bundle) {
                      ArrayList&lt;String&gt; arrayList = bundle.getStringArrayList (SpeechRecognizer.RESULTS_RECOGNITION);
                      if(arrayList!=null){
                          textView.setText (arrayList.get (0));
                          QUERY = arrayList.get (0);
                      }else {
                          Toast.makeText (MainActivity.this, "Array List is null", Toast.LENGTH_SHORT).show ();
                      }
                  }
  
                  @Override
                  public void onPartialResults(Bundle bundle) {
  
                  }
  
                  @Override
                  public void onEvent(int i, Bundle bundle) {
  
                  }
              });
  
              speechIntent = new Intent (RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
              speechIntent.putExtra (RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
              speechIntent.putExtra (RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault ());
          }
  
          public void start(View v) {
              speechRecognizer.startListening (speechIntent);
          }
  
          public void data(View v){
              Toast.makeText (this, QUERY, Toast.LENGTH_SHORT).show ();
              Async async = new Async ();
              async.execute ();
              if(DATA!=null){
                  textView1.setText (DATA);
              }
          } }
  
      class Async extends AsyncTask&lt;Void, Void, Void&gt;{
  
          String line = "";
          String data = "";
  
          @Override
          protected Void doInBackground(Void... voids) {
              try {
                  data=null;
                  Log.e("Query in url", MainActivity.QUERY);
                  URL url = new URL ("https://api.dialogflow.com/v1/query?v=20150910&amp;contexts=[]&amp;lang=en&amp;query="
      + MainActivity.QUERY +"&amp;sessionId=bee67580-d05c-47f6-8d64-a6218c3913e1");
                  URLConnection httpURLConnection = url.openConnection ();
                  httpURLConnection.setRequestProperty ("Authorization", "Bearer 
              CONFIDENTIAL KEY");
                  InputStream inputStream = httpURLConnection.getInputStream ();
                  BufferedReader bufferedReader = new BufferedReader (new 
                   InputStreamReader (inputStream));
                  while ((line = bufferedReader.readLine ()) != null) {
                      data += line;
                  }
              } catch (MalformedURLException e) {
                  Log.i ("PROBLEM", "URL");
              } catch (IOException e) {
                  Log.i ("PROBLEM", "IOEXCEPTIONe");
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(Void aVoid) {
              MainActivity.DATA = data;
              super.onPostExecute (aVoid);
          }  }
  </code></pre>