Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// runs a method every 2000ms
// example runThisEvery2seconds();
}
}, 2000);
} //end of OnCreate
public void runThisEvery2seconds()
{
//code that runs every 2 seconds
Toast.makeText(getBaseContext(), "Run from timer", Toast.LENGTH_SHORT);
}
目前我已经尝试过了,但没有出现 Toast 消息。不知道你是否被允许这样做,但总的来说,如果我实际上在 runThisEvery2seconds() 中执行代码,除了 Toast,它会每 2 秒运行一次吗?