📜  在特定时间后调用函数 java android - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:09.643000             🧑  作者: Mango

代码示例2
Runnable mToastRunnable;
Handler mHandler = new Handler();



  //create runnable for delay
       mToastRunnable = new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MainActivity.this, "This is a delayed toast", Toast.LENGTH_SHORT).show();
                mHandler.postDelayed(this, 3000000);
                getlocation();
            }
        };
//start
 mToastRunnable.run();

//stop
 mHandler.removeCallbacks(mToastRunnable);