public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); new Handler().postDelayed(new Runnable(){ public void run() { Intent mainIntent = new Intent(SplashActivity.this,MainActivity.class); SplashActivity.this.startActivity(mainIntent); SplashActivity.this.finish(); }}, 10000); }
?
在API中对于Handler的postDelayed方法描述如下:
Android API 写道
final boolean postDelayed(Runnable r, long delayMillis) Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.
?
将Runnable对象r在经过deleyMillis的时间后加入到消息队列,也就是讲过多久以后做什么事情就可以了。看起来很简单,有点类似于HTML里面的setTimeout和setInternal方法,使用也非常简单。
?