公共类Splash扩展了Activity {
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle Samiloveschicken) {
// TODO Auto-generated method stub
super.onCreate(Samiloveschicken);
setContentView(R.layout.splashscreen);
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
ourSong.start();
final Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}
finally{
Intent openMainActivity = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(openMainActivity);
Splash.this.finish();
overridePendingTransition(R.anim.mainfadein, R.anim.splashfadeout);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
ourSong.release();
super.onPause();
finish();
}
}
我是初学者,我尝试过onClickListener,其他各种事情都无济于事。 我似乎无法知道在哪里放这种方法。当触摸屏幕时,我能够中断睡眠(5000)。
答案 0 :(得分:0)
也许你可以设置一个名为interruptThread = false;
的全局标志然后在onTouchListener()上你可以设置interruptThread = true;
睡觉前(5000);做一个检查
if(interruptThread) {
thread.interrupt();
} else {
sleep(5000);
}
答案 1 :(得分:0)
试试这段代码,这可能会对你有帮助.......
public boolean onTouchEvent(MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_UP) {
ontouch = true;
startActivity(new Intent(your next activity));
finish();
return true;
}
return false;
};