0

公共类 Splash 扩展 Activity {

媒体播放器我们的歌曲;

@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)。

4

2 回答 2

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;

};
于 2013-06-07T09:37:48.673 回答
0

也许您可以设置一个名为 interruptThread = false; 的全局标志;

然后在 onTouchListener() 你可以设置 interruptThread = true;

睡前(5000);检查

if(interruptThread) { 
   thread.interrupt(); 
} else { 
  sleep(5000); 
}
于 2013-06-06T21:08:04.170 回答