title: Creating conditions inside a Runnable in android
body: <p>I've created a code that reads data thrown to my android device from an Arduino. It goes like this:</p>
  
  <pre><code> public void run() {
          byte[] buffer = new byte[1024];
          int bytes;
          final StringBuilder readMessage = new StringBuilder();
          while (true) {
              try {
                  bytes = connectedInputStream.read(buffer);
                  final String string_now = new String(buffer, 0, bytes);
                  readMessage.append(string_now);
                  // final int finalBytes = bytes;
                  runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          tvBPM.setText(string_now);
                          readMessage.setLength(0);
                      }
                  });
              } catch (IOException e) {
                  Toast.makeText(getApplicationContext(),"Connection Lost!",Toast.LENGTH_LONG).show();
              }
          }
      }
  </code></pre>
  
  <p>This code is located inside my 'private class ThreadConnected extends Thread'</p>
  
  <p>Now the values held by string_now are numbers. I want to tell the user if the value stored there is greater than 150 or less than 50. Here's a code I've tried but I doesn't fully work.</p>
  
  <pre><code>runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
                     final int getValue = Integer.getValue(Integer.parseInt(string_now));
                     if (getValue &gt; 150 || getValue &lt; 50) {
                        Toast.makeText(getApplicationContext, "Unstable", Toast.LENGTH_SHORT).show(); }
                     else {
                      tvBPM.setText(string_now);
                      readMessage.setLength(0); }
                  }
              });
  </code></pre>
  
  <p>Any tips on how I can make this work? Thank you.</p>