public class MainActivity extends AppCompatActivity {
private int count=3;
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
if (count==0){
Intent intent=new Intent(MainActivity.this,startActivity.class);
startActivity(intent);
MainActivity.this.finish();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
Timer timer=new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (count>0){
count--;
handler.sendEmptyMessage(0);
}
}
},0,1000);
}
}