【发布时间】:2014-03-13 10:15:37
【问题描述】:
在我的应用程序中,Activities 很少。问题是当我想关闭一个应用程序时,我的一个活动不会终止,而当我重新打开应用程序时,这个活动会首先出现。
就我而言,这可能是使用Handler 的问题。
在此活动中,我使用onTouchListener 中的Handler 旋转图像,同时使用Runnable,同时按下按钮。释放按钮后,我删除回调并调用另一个方法来启动下一个活动。
public void ListenTo(){
MatchTime.setOnTouchListener(new OnTouchListener(){
long time_start=0;
long time_end=0;
@Override
public boolean onTouch(View view, MotionEvent event) {
matchHandler = new Handler();
if (event.getAction() == MotionEvent.ACTION_DOWN ) {
time_start=System.currentTimeMillis();
matchHandler.post(matchAction);
return true;
}
if (event.getAction() == MotionEvent.ACTION_UP ) {
time_end=System.currentTimeMillis();
long TimeCounted=time_end-time_start;
matchHandler.removeCallbacks(matchAction);
matchHandler = null;
SaveAndSend(TimeCounted);
return true;
}
return false;
}
Runnable matchAction = new Runnable() {
@Override public void run() {
Face = (ImageView) findViewById(R.id.MatchTimeImage);
Face.setRotation(Face.getRotation()+9);
matchHandler.postDelayed(this, 25);
}
};
});
}
我的问题是:
Handler 线程在 Android 自行终止之前不会停止,我做错了什么?
【问题讨论】:
标签: java android activity-lifecycle android-handler