实现Loading页显示几秒后跳转到主页面
Thread开启新线程方式
loading页面内容:
Thread loadingThread = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(2000);//loading页面的暂停时间,2秒
//跳转到主页面
Intent intent = new Intent(getContext(), MainActivity.class);
startActivity(intent);
} catch (InterruptedException e) {
// TODO: handle exception
}
}
});
loadingThread.start();
Timer启用定时器延时方式
loading页面内容:
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
Intent intent = new Intent(getContext(), MainActivity.class);
startActivity(intent);
}
};
timer.schedule(task, 2 * 1000);//延时2秒后启动计时器,只执行一次