title: Handler Runnable runs even after activity exit
body: <p>I am updating the text user types in a textview to database every 5 seconds.
  The handler collects data from textview and save it to database.
  But the update code runs even after I press back button and return to MainActivity.</p>
  
  <p>How can I stop running the code after exiting from activity.</p>
  
  <pre><code>  public class CreateBoxActivity extends AppCompatActivity {
      Long current_BoxID  = null, parent_BoxID = null;
      Handler h=new Handler();
  
         @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_create_box);
          h.post(new Runnable(){ //Run this every five seconds to update the data
              @Override
              public void run() {
  
                  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                  String editeddate = sdf.format(Calendar.getInstance().getTime());
                  String titleText =  ((EditText)findViewById(R.id.new_box_title)).getText().toString();
                  String descriText =  ((EditText)findViewById(R.id.new_box_descri)).getText().toString();
                  Boxes nbx = new Boxes(1, null , titleText, descriText, editeddate, editeddate);
                  BoxesController.UpdateBox(nbx);
  
                  h.postDelayed(this,5000);
              }
          });
      }
  </code></pre>