OnTouchListener 工作不正常
我在使用 OnTouchListener
时遇到一些问题。我希望每次当用户触摸屏幕进入某个活动时。问题是,当我触摸屏幕时,它正在对当前活动进行刷新之类的操作并启动(当前活动包含一个 ViewFlipper,当触摸屏幕时,viewflipper 开始从头开始翻转) )。仅在第二次触摸时,应用程序才会进入下一个活动。谁能帮我解决这个问题吗?
我当前的活动扩展了 OnTouchListener
,我设置了 myviewflipper.setonTouchListener(this)
,我的 onTouch()
方法是:
@Override
public boolean onTouch(View v, MotionEvent event) {
finish=true;
Intent intent = new Intent(getBaseContext(), FinishApplication.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
return true;
}
触摸屏幕后调用onPause()
和 onResume()
。在 onResume() 方法中,我启动了一些计时器来进行一些更新(当进行更新时,幻灯片开始),我认为这就是我的活动刷新的原因。仅在触摸屏幕后,我将变量布尔 finish
设置为 true
,并且仅当 finish
为 false
时才开始更新> 但不工作。我的变量未设置为 true。还有其他想法如何解决这个问题吗?
@Override
protected void onResume() {
super.onResume();
System.out.println("OnResume ViewPlaylist!!");
t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
Imalive();
}
});
}
}, 300, 30000);
if (finish != true) {
System.out.println("Start update!");
update = new Timer();
update.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
updateItems();
}
});
}
}, 30000, 20000);
} else {
finish = true;
Intent intent = new Intent(SlideShow.this, FinishApplication.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
}
I have some problems with OnTouchListener
. I want that everytime when user touch the screen to go to a certain activity. The problem is that when I touch the screen it is making something like an refresh for the present activity and it starts (the current activity contains a ViewFlipper
and when the screen is touched the viewflipper starts flipping from the begining). Only at the second touch the app goes to next activity. Can anyone help me to solve this?
My current activity extends OnTouchListener
, I set myviewflipper.setonTouchListener(this)
and my onTouch()
method is :
@Override
public boolean onTouch(View v, MotionEvent event) {
finish=true;
Intent intent = new Intent(getBaseContext(), FinishApplication.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
return true;
}
After I touch the screen is called onPause()
and onResume()
. On onResume()
method I start some timers for some updates (when updates are made, the slideshow starts) and I think that's the reason why my activity is refresh. I set a variable boolean finish
to true
only after the screen is touch and start the updates only if finish
is false
but is not working. My variable is not set to true. Any other idea how can I solve this ?
@Override
protected void onResume() {
super.onResume();
System.out.println("OnResume ViewPlaylist!!");
t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
Imalive();
}
});
}
}, 300, 30000);
if (finish != true) {
System.out.println("Start update!");
update = new Timer();
update.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
updateItems();
}
});
}
}, 30000, 20000);
} else {
finish = true;
Intent intent = new Intent(SlideShow.this, FinishApplication.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过在
onPause()
方法上调用finish()
来解决这个问题。I solve this by calling
finish()
ononPause()
method.