【Android】实现Activity页面暂停几秒后跳转的两种方法
程序员文章站
2022-03-03 08:53:23
...
方法一
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MainActivity.this,
ExampleActivity.class);
startActivity(intent);
}
}, SPLASH_DISPLAY_LENGHT);
方法二
final Intent localIntent = new Intent(this, ExampleActivity.class);
Timer timer = new Timer();
TimerTask tast = new TimerTask() {
@Override
public void run() {
startActivity(localIntent);
}
};
timer.schedule(tast, SPLASH_DISPLAY_LENGHT);
使用范例
package com.app.weixin;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import com.app.wexin.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class WelcomeActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
final Intent localIntent = new Intent(this, Tabs.class);
Timer timer = new Timer();
TimerTask tast = new TimerTask() {
@Override
public void run() {
startActivity(localIntent);
}
};
timer.schedule(tast, 1500);
}
}
此为暂停1.5秒后跳转。上一篇: 在几秒之后跳转页面
下一篇: P1059 明明的随机数(桶排序)