title: Warning: Do not place Android context classes in static fields; this is a memory leak (and also breaks Instant Run)
body: <p>Android Studio:</p>
  
  <blockquote>
    <p>Do not place Android context classes in static fields; this is a
    memory leak (and also breaks Instant Run)</p>
  </blockquote>
  
  <p>So 2 questions:<br><br>
  #1 How do you call a <code>startService</code> from a static method without a static variable for context?<br>
  #2 How do you send a localBroadcast from a static method (same)?</p>
  
  <p>Examples:</p>
  
  <pre><code>public static void log(int iLogLevel, String sRequest, String sData) {
      if(iLogLevel &gt; 0) {
  
          Intent intent = new Intent(mContext, LogService.class);
          intent.putExtra("UPDATE_MAIN_ACTIVITY_VIEW", "UPDATE_MAIN_ACTIVITY_VIEW");
          mContext.startService(intent);
      }
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>        Intent intent = new Intent(MAIN_ACTIVITY_RECEIVER_INTENT);
          intent.putExtra(MAIN_ACTIVITY_REQUEST_FOR_UPDATE, sRequest));
          intent.putExtra(MAIN_ACTIVITY_DATA_FOR_VIEW, sData);
          intent.putExtra(MAIN_ACTIVITY_LOG_LEVEL, iLogLevel);
          LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
  </code></pre>
  
  <p>What would be the correct way to do this without using <code>mContext</code>?</p>
  
  <p>NOTE: I think my main question might be how to pass context to a class from which the calling method lives.</p>