I want to stop a thread when a back button is pressed.
I'm using Handler
.
You need to use Handler
's removeCallbacks()
function.
Sample code:
@Override
public boolean onBackPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
handler.removeCallbacks(yourRunnable);
return true;
}
return super.onKeyDown(keyCode, event);
}
You can't use either stop
or destroy
methods.
In the onStop
method you have to use this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With