Handler基本用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Handler基本用法相关的知识,希望对你有一定的参考价值。

1.
mHandler = new Handler();
mRunnable = new Runnable() {
@Override
public void run() {
currentPosition++;
Log.d("recyclerBanner", currentPosition + " ");
mOverFlyingLayoutManager.scrollToPosition(currentPosition);
// recyclerView.smoothScrollToPosition(currentPosition);
mHandler.postDelayed(this, 3000);
}
};
mHandler.postDelayed(mRunnable, 3000);

2.项目中实践用法
mainHandler.sendEmptyMessageDelayed(Url.Banner,3000);
@Override
protected void disposeMainHandlerCallMethod(Message msg) {
super.disposeMainHandlerCallMethod(msg);
switch(msg.what){
case Url.Banner:
currentPosition++;
Log.d("recyclerBanner", currentPosition + " ");
mOverFlyingLayoutManager.scrollToPosition(currentPosition);
// recyclerView.smoothScrollToPosition(currentPosition);
mainHandler.sendEmptyMessageDelayed(Url.Banner,3000);
break;
default:break;
}//end of switch
}
 

以上是关于Handler基本用法的主要内容,如果未能解决你的问题,请参考以下文章

Handler基本用法

Android Studio - 如何从片段中停止 handler.postDelayed?

set_exception_handler函数在ThinkPHP中的用法

python调试:pdb基本用法(转)

Android之Handler用法总结

安卓Handler消息处理机制详解