当我点击一个按钮(Button1)时,我想在屏幕上显示一张图片(在全屏模式下),并播放一首歌(congrats.mp3)。10秒后,用户将被重定向到另一个使用意图(SecondGame.class)的活动。我怎么能这样做呢?
发布于 2018-04-19 07:53:48
您可以通过使用10秒后运行的Handler线程来实现它。
将下面的代码放入按钮的onClickListener()方法中,即当您单击button.Before重定向时,您可以为要执行的操作放置任何代码。
private int SPLASH_TIME_OUT=10000; // for 10 seconds
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Code here what you want before redirecting
// e.g. hide picture you showed
Intent intent = new Intent(CurrentActivity.this, SecondGame.class);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(SplashScreen.this);
startActivity(intent, options.toBundle());
finish();
}
},TIME_OUT); // parameter to show for a particular time
}https://stackoverflow.com/questions/49915282
复制相似问题