gpt4 book ai didi

android 如何停止 mHandler.postDelayed

转载 作者:行者123 更新时间:2023-11-30 04:15:47 25 4
gpt4 key购买 nike

我有一个应用程序,我将 mHandler 用作计时器......它工作正常,然后 Runnable MuPdeteTimeTask 工作......这是一个代码......

    mHandlerTime.removeCallbacks(mUpdateTimeOutTask);
mHandlerTime.postDelayed(mUpdateTimeOutTask, delay_timeoutzz);

......................................

    private Runnable mUpdateTimeOutTask = new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "TimeOut of session is reached! Session will be force closed!", Toast.LENGTH_LONG).show();
new UploadTask().onCancelled();
}
};

我怎么能阻止它或想定义“延迟”的新含义????

最佳答案

你肯定可以做这样的事情,

取两个变量,

boolean delayedAgain = false;
long newDelayedTimeFromNow=5000;

然后在您的可运行应用逻辑中,

Runnable  mUpdateTimeOutTask = new Runnable() {             
@Override
public void run() {
if(delayedAgain)
{
delayedAgain = false;
mHandlerTime.postDelayed(this, newDelayedTimeFromNow);
return;
}
else
{
// DO JOB ON TIME.
}
}
};

现在从你的另一个任务,

if(somethingIsDone)
{
delayedAgain = true;
newDelayedTimeFromNow = 3000;
}

关于android 如何停止 mHandler.postDelayed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10043422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com