title: How can i stop sending messages which are sending in loop on click of an button in android
body: <p>I want to know how can I stop message sending in a loop.<br>
  When I press stop, messages are still sent.<br>
  I have provided a <code>stop()</code> method.</p>
  
  <pre><code>for (i = 0; i &lt; copy; i++) {
                  new Handler().postDelayed(new Runnable() {
  
                      @Override
                      public void run() {
                          if(stop!=1)
                              sms.sendTextMessage(number,null,message,sentPIn,pdelint);
                      }
  
                  }, 25000);
  
  
  stop method
  
  int stop=0;
  
  public void st(View view){
      Button b=(Button)findViewById(R.id.button2);
      b.setText("Stopped");
      stop=1;
  }
  </code></pre>