package com.example.lx123000;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView tv;
private int i = 5;
@SuppressLint("HandlerLeak")
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
tv.setText("引导页倒计时"+i+"秒后跳转");
if ((Integer)msg.obj==0){
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
finish();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = findViewById(R.id.tv);
new Thread(){
@Override
public void run() {
super.run();
while (i<=5){
i--;
Message msg = new Message();
msg.obj = i;
handler.sendMessage(msg);
try {
sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}.start();
}
}
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView tv;
private int i = 5;
@SuppressLint("HandlerLeak")
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
tv.setText("引导页倒计时"+i+"秒后跳转");
if ((Integer)msg.obj==0){
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
finish();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = findViewById(R.id.tv);
new Thread(){
@Override
public void run() {
super.run();
while (i<=5){
i--;
Message msg = new Message();
msg.obj = i;
handler.sendMessage(msg);
try {
sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}.start();
}
}