我有一个在“ RAW”上运行的视频
单击该按钮将转到下一个活动,但是“ SPLASH_TIME”仍在计数。
''Button btn_1; VideoView videoView2;
private static int SPLASH_TIME = 10000; // This is 10 seconds
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_pub2);
btn_1 = (Button) findViewById (R.id.line1);
btn_1.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick (View v) {
Toast.makeText (Pub2.this, "BOOOOAAAAAA", Toast.LENGTH_SHORT) .show ();
Intent orderDetail = new Intent (Pub2.this, Main2.class);
startActivity (orderDetail);
}
});
videoView2 = (VideoView) findViewById (R.id.videoView2);
videoView2.setVideoURI (Uri.parse ("android.resource: //" + getPackageName () + "/" + R.raw.crop));
videoView2.requestFocus ();
videoView2.start ();
new Handler (). postDelayed (new Runnable () {
@Override
public void run () {
// Do any action here. Now we are moving to next page
Intent mySuperIntent = new Intent (Pub2.this, MainActivity.class);
startActivity (mySuperIntent);
finish ();
}
}, SPLASH_TIME);
我可以继续参加新的活动,但是在“ SPLASH_TIME”完成后,SPLASH_TIME = 10000; 中断并转到给出的意图
Intent mySuperIntent = new Intent (Pub2.this, MainActivity.class);
startActivity (mySuperIntent);
答案 0 :(得分:1)
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
Intent mySuperIntent = new Intent (Pub2.this, MainActivity.class);
startActivity (mySuperIntent);
finish ();
}
});
答案 1 :(得分:0)
通过调用handler.removeCallbacksAndMessages(null)
停止处理程序。它将从处理程序中删除所有callBacks。在您的课程中定义一个处理程序
Handler mHandler= newHandler();
void foo(){
mHandler.postDelayed (new Runnable () {
@Override
public void run () {
// Do any action here. Now we are moving to next page
Intent mySuperIntent = new Intent (Pub2.this, MainActivity.class);
startActivity (mySuperIntent);
finish ();
}
}, SPLASH_TIME);
}
@Override onStop(){
super.onStop();
handler.removeCallbacksAndMessages(null);
}