我想在我的登錄屏幕出現之前運行設計頁面...所以,設計頁面如何能夠保持幾秒鐘?運行固定時間的活動,然後開始另一個活動
1
A
回答
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
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 :-)
快樂編碼
相關問題
- 1. 點擊 - 在一段時間後開始另一個活動
- 2. 開始另一個活動時不破壞主要活動
- 3. 獲取所有JSON響應,然後開始另一個活動
- 4. 行動意圖造成ActivityNotFoundException同時開始另一個活動
- 5. 暫停/恢復活動的另一個活動開始的Android
- 6. 如何開始新的活動並等待一段時間並開始另一個活動?
- 7. 如果在此活動中沒有特定活動的時間,則開始另一活動
- 8. 活動不能停止另一個活動,然後自己
- 9. Android aSyncTask並開始另一個活動
- 10. 錯誤,而開始另一個活動
- 11. Robotium - 從主要活動開始另一個活動
- 12. 從另一個活動運行的AsyncTask
- 13. 在創建另一個活動時打開對話框活動
- 14. 如何在另一項活動中開始活動?
- 15. 打開另一個活動時出錯?
- 16. 定時器後啓動一個活動
- 17. 在後臺開始活動
- 18. 如何在特定時間後致電另一個活動
- 19. 如何開始另一項活動?
- 20. 使活動計數減少3秒鐘,並自動開始另一個活動
- 21. 當開始另一個活動的好時機
- 22. 改善活動開始時間(AsyncTask?)
- 23. 開始活動執行onResume?
- 24. 開始活動時出錯
- 25. 如何減少從一個活動切換到另一個活動的時間?
- 26. 清除Android活動堆棧開始一個新的活動
- 27. Android - 從子活動onResume()開始一個完成的父活動()
- 28. 從一個非活動類別開始新的活動
- 29. 另一個人開始活動時會發生什麼?
- 30. 當檢測到網絡連接時開始另一個活動
感謝的傢伙對你有所幫助的名稱.... – 2011-03-31 05:52:52