title: Android: How to use a Handler handleMessage and access the reference to the MainActivity
body: <p>I have a service which receives a command from the Internet and launches a background thread. This thread is passed a handler from the service (the service is bounded and passed the handler) and sends a message to the handler to take a picture. I'm stuck on the implementation of the handler. </p>
  
  <pre><code>static Handler handler = new Handler() {
  
          @Override
          public void handleMessage(Message msg) {
              //TODO: Handle different types of messages
              mCamera.takePicture(null, null, MainActivity.this);
          }
  };
  </code></pre>
  
  <p>Questions:</p>
  
  <ul>
  <li>Does Handler need to be static? Without static, I get "This Handler class should be static or leaks might occur"</li>
  <li>Does mCamera need to be static? I've been told to make mCamera static, but why is this necessary? Is there a way to setup takePicture without making mCamera static?</li>
  <li>What's the proper way to pass the reference to MainActivity? Right now I get the error: "No enclosing instance of the type MainActivity is accessible in scope"</li>
  </ul>