title: Android Fragment getActivity() = null
body: <p>I'm using fragments in my application. And the very common problem while using them are the NPE when using getActivity(). I know we can solve it by checking if <code>getActivity() != null</code> every single time or checking if the fragment <code>isAdded()</code>. </p>
  
  <p>In one of my classes I'm getting activity's context in more than 60 places. Checking if getActivity()is not null or if the fragment is still added to the activity in all the places is making the code ugly,larger and non-maintainable. Is there any other way to handle this?
  Is it even possible to destroy the fragment(and stop any work it has been doing while being removed) when it is removed from the activity? </p>
  
  <p><a href="https://stackoverflow.com/questions/11631408/android-fragment-getactivity-sometime-returns-null/18078453#18078453">Also Is this way a suggested one?</a></p>