title: Android Application crashes in while loop
body: <p>I have an android app connected with my database using volley/JSON.I want to check continuously  the table "request" of a user in my database and when it has a value equal to 1 I want an alert message.I used while loop to handle it but the application crashes.Any ideas how to avoid using while?
  Here is my java code I run into the mainactivity in onCreate method:</p>
  
  <pre><code>     while(request!=1)  {
  
          Response.Listener&lt;String&gt; response1Listener = new Response.Listener&lt;String&gt;() {
              @Override
              public void onResponse(final String response) {
  
  
                  try {
                      JSONObject jsonResponse = new JSONObject(response);
  
  
                      request= jsonResponse.getInt("request");
                      requestorigin=jsonResponse.getString("requestorigin");
  
                       //Toast.makeText(MainActivity.this,"Request from    " + requestorigin ,Toast.LENGTH_LONG).show();
                      // Toast.makeText(MainActivity.this,"Request from    " + request ,Toast.LENGTH_LONG).show();
  
                      if(request==1)  {
                          Toast.makeText(MainActivity.this,"Request from    " + requestorigin ,Toast.LENGTH_LONG).show();
  
                      }
                  } catch (
                          JSONException e
                          )
                  {
                      e.printStackTrace();
                  }
              }
          };
  
          CheckRequest checkRequest = new CheckRequest(username,response1Listener);
          RequestQueue queue1 = Volley.newRequestQueue(MainActivity.this);
          queue1.add(checkRequest);
      }
  </code></pre>
  
  <p>And here is the CheckRequest class:</p>
  
  <pre><code>package com.example.sakis.multiplayerdemo;
  
  import com.android.volley.Response;
  import com.android.volley.toolbox.StringRequest;
  
  import java.util.HashMap;
  import java.util.Map;
  
  public class CheckRequest extends StringRequest {
      private static final String REGISTER_REQUEST_URL = "http://xxxxx.com/CheckRequest.php";
  private Map&lt;String, String&gt; params;
  
  public CheckRequest(String username, Response.Listener&lt;String&gt; listener) {
      super(Method.POST, REGISTER_REQUEST_URL, listener, null);
      params = new HashMap&lt;&gt;();
      params.put("username", username  );
  }
  
  @Override
  public Map&lt;String, String&gt; getParams() {
      return params;
  }
  }
  </code></pre>
  
  <p>The logcat shows this:</p>
  
  <pre><code>29582-29582/com.example.sakis.multiplayerdemo D/dalvikvm: VFY: replacing 
  opcode 0x6f at 0x120b 05-21 12:38:17.236 29582-    
  29582/com.example.sakis.multiplayerdemo E/dalvikvm: Could not find class 
  'android.os.PersistableBundle', referenced from method 
  com.example.sakis.multiplayerdemo.MainActivity.access$super 05-21 
  12:38:17.236 29582-29582/com.example.sakis.multiplayerdemo W/dalvikvm: VFY: 
  unable to resolve check-cast 222 (Landroid/os/PersistableBundle;) in 
  Lcom/example/sakis/multiplayerdemo/MainActivity; 
  </code></pre>