2013-04-05 76 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); 

这是最好的方式。

相关问题