//声明变量
private int recLen = 3;//跳过倒计时提示5秒 Timer timer = new Timer(); private Handler handler; private Runnable runnable;
// 文字控件的倒计时(写在 initn内)
timer.schedule(task, 1000, 1000);//等待时间一秒,停顿时间一秒
//写在和类内,和方法同级
TimerTask task = new TimerTask() {@Overridepublic void run() {runOnUiThread(new Runnable() { // UI thread@Overridepublic void run() {tv_tiaoguo.setText("跳过 " + recLen);if (recLen < 0) {timer.cancel();tv_tiaoguo.setVisibility(View.GONE);//倒计时到0隐藏字体}recLen--;}});}
};
//倒计时的w完毕的跳转(写在 init内)
handler = new Handler();
handler.postDelayed(runnable = new Runnable() {@Overridepublic void run() {//从闪屏界面跳转到首界面Intent intent = new Intent(Activity_Advertisement.this, MainActivity.class);startActivity(intent);finish();}
}, 3010);//延迟5S后发送handler信息
//点击 跳过(去主页)
intent = new Intent(Activity_Advertisement.this, MainActivity.class);
startActivity(intent);
finish();
//取消hander
if (runnable != null) {
handler.removeCallbacks(runnable);
}
//点击广告
//先跳主页
intent = new Intent(Activity_Advertisement.this, MainActivity.class);
intent.putExtra("type", "normal");
startActivity(intent);//在跳点击广告的页intent = new Intent(this, Activity_Web.class);intent.putExtra("url", listdata.get(0).getUrl());intent.putExtra("name", listdata.get(0).getName());
startActivity(intent);//跳转过广告取消线程
if (runnable != null) {handler.removeCallbacks(runnable);
}