java如何在单击按钮后停止“飞溅时间”?
我有一个关于“原始”的视频
单击按钮进入下一个活动,但“飞溅时间”仍在计数
''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 ("安卓.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);
# 1 楼答案
通过调用
handler.removeCallbacksAndMessages(null)
停止处理程序。它将从处理程序中删除所有回调。在类中定义一个处理程序# 2 楼答案