Here is an operation that is performed every once in a while until the timing operation is turned off:
Copy the codeThe code is as follows:
final Handler handler = new Handler();
Runnable runnable = new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
// Add the executed code here
(this, 50);// 50 is the delay time
}
};
(runnable, 50);// Turn on the timer and perform the operation
(this);// Turn off timer processing
The following is to execute an operation once every once a while later, and after execution, it will no longer be executed.
Copy the codeThe code is as follows:
final Handler handler = new Handler();
runCount = 0;// Global variable used to determine whether it is the first execution
Runnable runnable = new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
if(runCount == 1){// The first execution is turned off and the timing is executed
// Add the executed code here
(this);
}
(this, 50);
runCount++;
}
};
(runnable, 50);// Turn on the timer and perform the operation