2011-03-29 50 views

回答

0

您可以使用啓動畫面的概念來做到這一點。 請看下面的代碼:

public class SplashScreen extends Activity { 
    protected boolean _active = true; 
    protected int _splashTime = 2000; // time to display the splash screen in ms 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
     Thread splashTread = new Thread() { 
       @Override 
       public void run() { 
        try { 
         int waited = 0; 
         while(_active && (waited < _splashTime)) { 
          sleep(100); 
          if(_active) { 
           waited += 100; 
          } 
         } 
        } catch(InterruptedException e) { 
         // do nothing 
        } finally { 
         finish(); 

         startActivity(new Intent("com.live.A")); 
         stop(); 
        } 
       } 
      }; 
      splashTread.start(); 
    } 

} 

其中A是你想要的啓動畫面後,顯示屏幕和com.live是你的包名

希望這將幫助你:)

+1

感謝的傢伙對你有所幫助的名稱.... – 2011-03-31 05:52:52

1
new Handler().postDelayed(new Runnable() { 


     public void run() { 

      /* Create an Intent that will start the Second-Activity. */ 

      Intent mainIntent = new Intent(YourFirstActivity.this, 
        YourSecondActivity.class); 

      YourFirstActivity.this.startActivity(mainIntent); 

      YourFirstActivity.this.finish(); 

     } 

    }, 2000); 
1

與上面幾乎一樣,添加了1個:屏幕上的觸摸移除了Spashscreen:

public class SplashScreen extends Activity { 

protected boolean _active = true; 
protected int _splashTime = 5000; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 

    // thread for displaying the SplashScreen 
    Thread splashTread = new Thread() { 
     @Override 
     public void run() { 
      try { 
       int waited = 0; 
       while(_active && (waited < _splashTime)) { 
        sleep(100); 
        if(_active) { 
         waited += 100; 
        } 
       } 
      } catch(InterruptedException e) { 
       // do nothing 
      } finally { 
       finish(); 
       GoToMain(); 
       stop(); 
      } 
     } 
    }; 
    splashTread.start(); 
} 
public void GoToMain(){ 
    Intent i = new Intent(this, MainActivity.class); 
    startActivity(i); 
} 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_DOWN) { 
     _active = false; 
    } 
    return true; 
} 

}

MainActivity是下一個活動的OFC :-)

快樂編碼

相關問題