【发布时间】:2015-04-07 05:47:31
【问题描述】:
我需要了解如何检测用户是否触摸了屏幕。
预期结果:-当用户触摸屏幕时,它应该跳过启动屏幕并移动到主要活动。
问题:-每当用户触摸屏幕时,就会跳过启动画面,但在后台 sleep(10500) 中的 try 块会继续运行,并且随着时间的推移,主 Activity 会再次启动,即它会打开两次。
到目前为止我做了什么:-我尝试做while循环并给出一个条件,如果条件满足(触摸)然后中断。但我似乎没有得到正确的工作条件。 启动画面代码:-
@Override
protected void onCreate(Bundle splashState) {
// TODO Auto-generated method stub
super.onCreate(splashState);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
ourSong.start();
Thread timer = new Thread() {
public void run() {
do
{
try {
//if(onTouchEvent(null))
// break;
sleep(10500);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
startActivity(new Intent("com.first.MAINACTIVITY"));
}
}while(false);
}
};
timer.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
startActivity(new Intent("com.first.MAINACTIVITY"));
finish();
ourSong.release();
}
return super.onTouchEvent(event);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
ourSong.release();
}
如果在 try 块中提供了语句,因此如果满足条件,它将中断。但我不知道该条件。需要有关条件的帮助。 谢谢。
【问题讨论】:
标签: android touch-event