在视图创建的时候,先判断handler是否为空,为空就新建,在视图回收的时候,要移除所有的回调,并置空handler
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mHandler == null) { mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); } }; } return view; } @Override public void onDestroyView() { super.onDestroyView(); mHandler.removeCallbacksAndMessages(null); mHandler = null; }