如何停止 onDestroy() android Studio 中的闪烁方法?

How to stop blink method in onDestroy() android Studio?

我想在 onDestroy() 中停止处理程序。代码如下。 blink() 方法因特殊原因在 activity 中调用,但想停止对 destroy 方法的服务。

final Handler handler = new Handler();
private void blink() {
    PrintLog.log("On", "Blink Thread");
    new Thread(new Runnable() {
        @Override
        public void run() {
            int timeToBlink = 1000;    //in milissegunds
            try {
                Thread.sleep(timeToBlink);
            } catch (Exception e) {
            }
            handler.post(new Runnable() {
                @Override
                public void run() {

                    if (text_ATMCardInstruction.getVisibility() == View.VISIBLE) {
                        text_ATMCardInstruction.setVisibility(View.INVISIBLE);
                    } else {
                        text_ATMCardInstruction.setVisibility(View.VISIBLE);
                    }
                    blink();
                }
            });
        }
    }).start();
}

@Override
protected void onDestroy() {

    // what is code here?
    PrintLog.log("Stop", "serviceStop");
    super.onDestroy();
}

处理 treadRunning 布尔值 onDestroy() 方法设置 treadRunning = false;

private void blink() {
    PrintLog.log("On", "Blink Thread");

    if (treadRunning) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                int timeToBlink = 1000;    //in milissegunds
                try {
                    Thread.sleep(timeToBlink);
                } catch (Exception e) {
                }
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (text_ATMCardInstruction.getVisibility() == View.VISIBLE) {
                            text_ATMCardInstruction.setVisibility(View.INVISIBLE);
                        } else {
                            text_ATMCardInstruction.setVisibility(View.VISIBLE);
                        }
                        blink();
                    }
                });
            }
        }).start();
    } else {
        PrintLog.log("On", "Blink Thread Stop");
        new Thread(new Runnable() {
            @Override
            public void run() {
                text_ATMCardInstruction.setVisibility(View.INVISIBLE);
            }
        }).interrupt();
    }
}