title: Activity is NULL in fragment, but not always in Android
body: <p>The <code>this.getActivity()</code> is NULL in my fragment, and is called from the actual activity itself.  This doesnt always happens but how can I fix this?</p>
  
  <pre><code>sportButton.setBackgroundColor(ViewHelper.getColor(this.getActivity()));
  </code></pre>
  
  <p><strong>EventActivity.java</strong></p>
  
  <pre><code>eventsFragment.setUpEvents(getEventApplication());
  </code></pre>
  
  <p><strong>EventsFragment.java</strong></p>
  
  <pre><code>public void setUpEvents(Application application) {
        sportButton.setBackgroundColor(ViewHelper.getColor(this.getActivity()));
  </code></pre>