Post Delay Method - Android

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 10:36:47
Mihir Shah

You can use removeCallbacks(runnable) method of the handler using which you are calling postDelayed() method. For example, if you used:

mHandler.postDelayed(mRunnable, mTime)

for refreshing the activity, then use

mHandler.removeCallbacks(mRunnable)

in onPause() method of the activity.

Make a sign of boolean in your postdelayed method. Init the sign as true,when the activity is finnished , set the value of sign as false.

You can use this piece of code to run after a 3 sec delay.

new Timer().schedule(new TimerTask() {          
    @Override
    public void run() {

        // run your code here    

    }
}, 3000);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!