I have a simple program with one TextView and two Buttons: Button1 and Button2.
Clicking on Button 1 will start a counter, increasing by 1 every 1 second and show res
You can introduce flag. Something like isPaused. Trigger this flag whenever 'Pause' button pressed. Check flag value in your timer task. Success.
Timer T=new Timer();
T.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable()
{
@Override
public void run()
{
myTextView.setText("count="+count);
count++;
}
});
}
}, 1000, 1000);
onClick(View v)
{
//this is 'Pause' button click listener
T.cancel();
}