title: Continue to run thread?
body: <p>I have a service and a thread inside it. I want to only keep running the thread while my shared preference variable is true. How can I accomplish this? I want something like this:</p>
  
  <pre><code>//My Service
  
  while(preferences.getBoolean("doIkeepRunningThread", false) == true){ //User wants me to continue to run this thread
  
  thread.continueToRun() //Not a real method, I just made it up to show what I want
  
   }
  </code></pre>
  
  <h2>Basically, I want to say, "as long as this variable (shared prefs) is true, keep running this thread, but as soon as its false, stop the thread."</h2>
  
  <p>Everything is in a service.</p>
  
  <p>The reason I want to implement this is because I have a settings screen where <strong>the user can choose to stop my thread</strong>. My problem is when the thread is currently running, and then the user decides to stop it, it will continue running.</p>
  
  <p>P.S. The service is never ending, and is constantly collecting data.</p>