title: Stop handler after the fragment has been destroyed
body: <p>I have a <code>Fragment</code> which sets up a <code>ListView</code> and creates a <code>Handler</code> to update the <code>Listview</code> periodically. However, it looks like the <code>Handler</code> still runs after the <code>Fragment</code> has been destroyed. </p>
  
  <p>The following is the code.</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      //boilerplate code
  
      final Handler handler = new Handler();
      handler.post(new Runnable() {
          @Override
          public void run() {
              assignAdapter();
              handler.postDelayed(this, 15000);
          }
      });
  
      return v;
  }
  </code></pre>
  
  <p>Updating the <code>ListView</code> after the destruction of the <code>Fragment</code> causes the app to crash. How can I cause the <code>Handler</code> to stop as the <code>Fragment</code> gets destroyed? I would also like to know what effects if any pausing the app has on the <code>Handler</code> as well.</p>