title: Android NullPointerException with static Objects
body: <p>For storing runtime data in my app I have a class with two static variables:</p>
  
  <pre><code>public class App {
    public static ClementineConnection mClementineConnection = null;
    public static Clementine mClementine = null;
  }
  </code></pre>
  
  <p>Those are initialized in the <code>onCreate</code> Method of the first Activity. This Activity does nothing but starting other activities depending on a state (is the app connected to server).</p>
  
  <p>If the App is idle or running in the background with a notification, sometimes a NullPointerException occurs in the other onCreate Methods when accessing one of the static variables. Somehow they get garbage collected.
  The App has a Service with a Thread running in the Background, so I thought there must be a reference all the time.</p>
  
  <p>Do you know how I can prevent those static variables from being garbage collected? While the app is connected to the server, the information must be available. Creating a new instance (eg. <code>Clementine.getInstance()</code>) is not an option.</p>
  
  <p>If you want to have a look at the code: <a href="https://code.google.com/p/clementine-remote-android/source/browse/" rel="nofollow">https://code.google.com/p/clementine-remote-android/source/browse/</a></p>