How to check a variable of main thread within a thread?

Viewed 907

I have a thread that is running:

public boolean shouldStopThread = false;

        new Thread(new Runnable() {
          @Override
          public void run() {
              try {

                   if(!shouldStopThread )
                     {
                      // Do my stop here
                     }
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
      }).start();

The problem is when I change the boolean from false to true the change isn't detected within the thread.

How do I get the boolean within the thread to detect the change?

3 Answers
Related