1

我有一个应用程序,我使用 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();
                       }
        };

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

4

1 回答 1

1

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

取两个变量,

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;
}
于 2012-04-06T12:31:43.713 回答