2013-04-05 77 views
-1

我是一名尋求幫助的青少年程序員。僅當我安裝應用程序時纔會打開Android Splash Screen

我寫了一個簡單的閃屏thingy,它只適用於我卸載並重新安裝應用程序。

請看看我是否做錯了什麼。

謝謝!

package ca._____.test; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Window; 
import android.view.WindowManager; 

public class splash extends Activity { 

private static String TAG = splash.class.getName(); 
private static long SLEEP_TIME = 5; // Sleep for some time 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar 

    setContentView(R.layout.spash_screen); 

    // Start timer and launch main activity 
    IntentLauncher launcher = new IntentLauncher(); 
    launcher.start(); 
    } 

private class IntentLauncher extends Thread { 
    @Override 
    /** 
    * Sleep for some time and than start new activity. 
    */ 
    public void run() { 
    try { 
     // Sleeping 
     Thread.sleep(SLEEP_TIME*1000); 
    } catch (Exception e) { 
     Log.e(TAG, e.getMessage()); 
    } 

    // Start main activity 
    Intent intent = new Intent(splash.this, MainActivity.class); 
    splash.this.startActivity(intent); 
    splash.this.finish(); 
    } 
} 
} 

回答

2

嘗試啓動IntentLauncher中的onResume(線程),由時間活動的的onResume()被調用創建活動,它會顯示在屏幕上。

第二和最好的事情是,你可以在的onResume()在處理開始MainActivity這樣

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

public void run() { 
    Intent intent = new Intent(splash.this, MainActivity.class); 
    splash.this.startActivity(intent); 
    splash.this.finish(); 
    } 
}, 5000); 

這是最好的方式。

相關問題