title: onPause() Android
body: <p>I have an app that connects to an URL every X seconds in an onPostExecute of a library that I had done. When I close the app or go back with the back button, it must stop with an override of the <code>onPause()</code> method on the main activity class.
  I want to control this with my own library to facilitate the creation of class for new developers, but if I override it on the library <code>onPause()</code> method, it continues making connections.
  There's a way to do these on my library?</p>
  
  <p>Here my code on the main class:</p>
  
  <pre><code>@Override
  public void onPause() {
      super.onPause();
      myLib.stopResource();
      myLib.flagRefresh = false;
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
       if (keyCode == KeyEvent.KEYCODE_BACK) {
          myLib.stopResource();
          myLib.flagRefresh = false;
          super.onBackPressed();
          return true;
       }
       return super.onKeyDown(keyCode, event);    
  }
  </code></pre>