等待五秒跳轉頁面
阿新 • • 發佈:2019-02-07
public class MainActivity extends Activity {
private int i=5;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
};
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.text);
Timer timer = new Timer();
TimerTask task=new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
if(i>=0){
text.setText((i--)+"");
}
}
});
if(i==0){
finish();
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
}
};
timer.schedule(task, 0, 1000);
}
private int i=5;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
};
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.text);
Timer timer = new Timer();
TimerTask task=new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
if(i>=0){
text.setText((i--)+"");
}
}
});
if(i==0){
finish();
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
}
};
timer.schedule(task, 0, 1000);
}