恢复后 Android Runnable 运行速度更快 [英] Android Runnable runs faster after Resume
本文介绍了恢复后 Android Runnable 运行速度更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 runnable,它每 1 秒输出一个变量的值.runnable 在我启动 mainActivity 时启动,并在后台运行整个应用程序.
I have a runnable that outputs a the value of a variable every 1 second. The runnable starts when I start the mainActivity and runs throughout the app in the background.
当我关闭应用程序(隐藏状态)并再次启动应用程序时,logcat 开始输出更快.每次我这样做时它都会变得更快.为什么?
When I close the app (hidden state) and start the app again, the logcat starts outputting faster. It goes faster everytime I do this. Why ?
@Override
public void onStart()
{
mHandler.postDelayed(myRunnable, 1000);
super.onStart();
}
public Runnable myRunnable = new Runnable()
{
@Override
public void run()
{
count ++;
android.util.Log.w(" SYNC ", "COUNT:"+count);
mHandler.postDelayed(myRunnable, 1000);
}
};
解决方案/编辑
谢谢大家的回答!我会给予信任.然而,是@pskink 发布了这个Android Runnable 在恢复后运行得更快 ,这为我解决了.
推荐答案
callremoveCallbacksAndMessages(null) 在调用 postDelayed 之前
call removeCallbacksAndMessages(null) before calling postDelayed
这篇关于恢复后 Android Runnable 运行速度更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文