title: How to make handler static to avoid leak, when I call non static methods from it?
body: <p>So I have a service which performs communication with some hardware via bluetooth. Service contains a Handler for receiving messages from Activities. This messages are commands/instruction for service what to do. Handler is simply defined as:</p>
  
  <pre><code>class IncomingHandler extends Handler {
          @Override
          public void handleMessage(Message msg) {
  
              switch (msg){
              case: blahblah ....
                 break;
              case: blahblah ....
                 break;
              }
    }
  }
  </code></pre>
  
  <p>Everything actually works without problems BUT lint gave me warning that leak might occur and I should make this Handler static... </p>
  
  <blockquote>
    <p><em>This Handler class should be static or leaks might occur. 
    Issue: Ensures that Handler classes do not hold on to a reference to an outer
    class Id: HandlerLeak In Android, Handler classes should be static or
    leaks might occur. Messages enqueued on the application thread's
    MessageQueue also retain their target Handler. If the Handler is an
    inner class, its outer class will be retained as well. To avoid
    leaking the outer class, declare the Handler as a static nested class
    with a WeakReference to its outer class.</em></p>
  </blockquote>
  
  <p>My problem is that I can't simply make Handler static cause I am calling non static methods depending of which message came to service. Some methods are calling other methods and there are a lot of them so it is impossible that I would need to make them all static, no? </p>
  
  <p>Here I would need advice from you more experienced developers. How to solve this issue? Thanks</p>