Android由一个activity 间隔5秒自动跳转到另外一个activity

时间:2022-05-12 12:05:12
Android由一个activity 间隔5秒自动跳转到另外一个activity

2013年10月10日18:03:42

//一、写一个定时器 5秒后开启
        final Intent localIntent=new Intent(FirstActivity.this,SecondActivity.class);  
        Timer timer=new Timer();  
        TimerTask task=new TimerTask(){  
             @Override  
             public void run(){  
              startActivity(localIntent);  
             }  
        };  
        timer.schedule(task,10000);
        
        
 //二、写一个线程  5秒后跳转,postDelayed(Runnable r, long delayMillis)
        new Handler().postDelayed(new Runnable() {
            public void run() {
                    final Intent mainIntent = new Intent(FirstActivity.this,SecondActivity.class);
                    FirstActivity.this.startActivity(mainIntent);
                    FirstActivity.this.finish();
                    overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
            }
       }, 5000);