It worked for me when I called CancelCallBacks(this) inside the post delayed runnable by handing it via a boolean
Runnable runnable = new Runnable(){
@Override
public void run() {
Log.e("HANDLER", "run: Outside Runnable");
if (IsRecording) {
Log.e("HANDLER", "run: Runnable");
handler.postDelayed(this, 2000);
}else{
handler.removeCallbacks(this);
}
}
};