title: Is there a "break" method for android.os.Looper?
body: <p>I'm new to Android development (coming from C/C++, Win32 world).</p>
  
  <p>I'm trying to write a single-threaded service that should process various kinds of callbacks (system events, timers).</p>
  
  <p>What I need is a (sort of) emulation of a modal message-processing loop. That is, I want to be able to call some function that waits until some specific criteria is satisfied. However, while waiting, the thread should process all the events "in background". Actually the condition we're waiting for is triggered by one of the callbacks.</p>
  
  <p>Moreover, those "modal message-processing loops" may be nested. That is, while waiting for one criteria, from within a callback I may need to run another message-processing loop, waiting to another criteria.</p>
  
  <p>And I don't want multi-threading. Everything should be processed within single thread.</p>
  
  <p>From what I found in the documentation the most close match to what I need is using something like <code>Handler.getLooper().loop()</code> to run the loop, and <code>Handler.getLooper().quitSafely()</code> to trigger loop break.</p>
  
  <p>However the documentation is somewhat confusing. It is unclear if it's allowed to call this function recursively. Also, it's unclear if after <code>quitSafely()</code> the loop can be used again. The documentation states that <code>quit()</code> is indeed the last function called for the looper, after which it's no more usable, however for <code>quitSafely()</code> it states that:</p>
  
  <blockquote>
    <p>pending delayed messages with due times in the future will not be delivered <strong>before the loop terminates</strong>. </p>
  </blockquote>
  
  <p>Does it mean that after the loop terminates - it's usable again?</p>
  
  <p>If not, what are the other options available? Can I control the message loop explicitly? Something similar to <code>GetMessage</code> / <code>DispatchMessage</code> in Win32?</p>