title: Comparing data from JSON
body: <p>I am using a service to get a count value from JSON array which is for example <code>count=3</code>.<br>
  Service Runs after every 20 second and returns a new count value.
  Now For example we have new count value <code>count=3</code>.<br>
  I want to compare <strong>new count</strong> value with the previous <strong>count</strong> value.<br>
  For Example:<br>
  1st Time Service Runs:</p>
  
  <pre><code>count=3
  </code></pre>
  
  <p>2nd Time Service Runs:</p>
  
  <pre><code>count=5
  </code></pre>
  
  <p>Now How to compare count=5 to count = 3.</p>
  
  <p>3rd Time Service Runs:  </p>
  
  <pre><code>count=6
  </code></pre>
  
  <p>Now compare <code>count=6</code> to <code>count =5</code>
  And so on...<br>
  Any Help is appreciated. Thanks in Advance.</p>
  
  <p>Below is MyService.class  </p>
  
  <pre><code>public class GettingUpdate extends Service {
  private int first=0;
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      Toast.makeText(this,"Quack Toast",Toast.LENGTH_SHORT).show();
      new ServAsynch().execute();
      return super.onStartCommand(intent, flags, startId);
  }
  
  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  private class ServAsynch extends AsyncTask {
  
  
      @Override
      protected Object doInBackground(Object[] objects) {
          String urlQuack="Someurl";
  
          try {
              System.out.println("test");
              URL url = new URL(Someurl);
              URLConnection connection = url.openConnection();
              InputStream inputStream = connection.getInputStream();
              BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
              StringBuilder result = new StringBuilder();
              String line;
              while((line = reader.readLine()) != null){
  
                  result.append(line);
  
              }
              System.out.println("testRes");
              System.out.println("RESULT:" + result);
              JSONObject jsonObject = new JSONObject(String.valueOf(result));
              JSONObject jo = jsonObject.optJSONObject("metadata");
              String count = jo.optString("count");
              System.out.println("Count: "+count);
              first =Integer.parseInt(count);
              }  catch (Exception e) {
              System.out.println(e);
          }
          return  null;
      }
  
  
      @Override
      protected void onPostExecute(Object o) {
          super.onPostExecute(o);
  
  
      }
  }enter code here
  </code></pre>