Post Delay Method - Android

前端 未结 3 1218
南旧
南旧 2021-01-15 08:02

I used postedDelayed method to refresh my Activity, which works fine. But the problem is that even when I press the Back button postdelayed method call back the previous act

相关标签:
3条回答
  • 2021-01-15 08:49

    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);
    
    0 讨论(0)
  • 2021-01-15 08:53

    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.

    0 讨论(0)
  • 2021-01-15 08:56

    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.

    0 讨论(0)
提交回复
热议问题