title: service in infinite loop android
body: <p>I want to call a service which repeatedly queries a Parse.com database and monitors a specific attribute.Here's what Ive got so far:</p>
  
  <pre><code>public class Battle extends Service {
  @Override
  public int onStartCommand(Intent intent,int flags,int startId)
  { 
      Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
       ParseUser currentUser = ParseUser.getCurrentUser();
       username = currentUser.getString("username");
      findinBackground();
  
       return START_STICKY;
  }
  
  
  
  
  private void findinBackground(){
  //public void run() {
      // TODO Auto-generated method stub
      while(true)
      {
      query = ParseUser.getQuery();
       query.whereEqualTo("isAttacking", username);
       query.findInBackground(new FindCallback&lt;ParseUser&gt;() {
            public void done(List&lt;ParseUser&gt; objects, ParseException e) {
                if ((e == null)&amp;(objects.size() != 0))
              {
                  // The query was successful.
  
                      ParseUser attacker = objects.get(0);
                      String attackerName = attacker.getUsername();
                      Log.i("ambustest",attackerName);
                      makeToast(attackerName);
  
              } 
                else
                {
                  Log.i("fd","Something went wrong.");
              }  
            }
          });
      }
  }
  
  }
  </code></pre>
  
  <p>This code compiles fine but stops responding at runtime.Here's my logcat:
  <img src="https://i.stack.imgur.com/f8mi0.png" alt="Logcat"></p>