title: Synchronizing handler creation, and accessing
body: <p>im getting sometimes null pointer exception while accessing handler created in thread.</p>
  
  <p>I`m using two approaches. </p>
  
  <p>One is service with thread, in which i create handler and access it by service method.
  Second is Thread created in activity, in which i`m making Thread, starting it, and making handler.</p>
  
  <p>Problem is quite simple, handler is created asynchronously to main thread. And i'am accessing it in main (gui thread), so sometimes it will create, and sometimes it will be null at time of getting it.</p>
  
  <p>i could make on gui thread while(handler == null){
  }
  but it's really bad solution. I`m looking for some elegant way to do this.</p>
  
  <p>Everything is in main thread.</p>
  
  <pre><code>Thread t = new Thread(new Runnable {
  Looper.prepare();
  handler = new Handler();
  Looper.Loop();
  }
  handler.post(new Runnable{}) //at this point sometimes handler is still null. 
  and it is created like few ms later. But still at this point i need valid handler
  to background thread
  </code></pre>