Android中Activity处理Handler消息时,frame-animation会卡顿
项目中要实现一个UI,要有进度滚动的动画以及步骤更新。
进度滚动的动画是采用帧动画的方式实现,步骤更新是采用的Handler机制进行更新。
UI是在主线程中的,在后台的service中调用Activity的handler进行msg发送,在Activity中根据接收到的msg进行步骤的更新处理。
现在的问题是,每次发送msg时,animation都会卡顿一下。开始是怀疑步骤更新的时候,对checkbox打钩影响的,现在把这部分代码注释掉后,同样会卡顿。有没有大神帮忙指导下,非常感谢!
Activity中接收msg处理如下:
case VdmcMsgHandler.MSG_TYPE_TASK_COMPLETE:{
// checkBox1.setVisibility(1);
// checkBox1.setChecked(true);
break;
}
service中发送msg如下:
NormalActivity.getInstance().handler.sendMessage(VdmcMsgHandler.MSG_TYPE_TASK_COMPLETE);
动画是放在onWindowFocusChanged中实现的:
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
Log.i(TAG, "onCreate");
setContentView(R.layout.taskactivity);
//check progress animation
animationImage = (ImageView)findViewById(R.id.hfaanimationimage);
}
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
Log.i(TAG, "onWindowFocusChanged");
animationImage.setImageResource(R.drawable.animation);
animationDrawable = (AnimationDrawable) animationImage.getDrawable();
animationDrawable.start();
}