当前位置: 代码迷 >> Android >> 【Android】实现Activity页面暂停几秒后跳转的两种步骤
  详细解决方案

【Android】实现Activity页面暂停几秒后跳转的两种步骤

热度:89   发布时间:2016-04-28 08:04:57.0
【Android】实现Activity页面暂停几秒后跳转的两种方法

方法一

        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秒后跳转。

  相关解决方案