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

你可能感兴趣的:(android,页面,暂停,跳转)