2013-08-28 162 views
0

我的項目的一部分我想使用啓動畫面。代碼一切正常,但不幸的是啓動畫面不會在啓動時加載。 我的清單文件是啓動畫面不加載

<activity 
    android:label="@string/app_name" 
    android:name="com.example.GamePlay.SplashScreen" 
    android:configChanges="orientation|keyboardHidden" 
    android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" 
    android:screenOrientation="landscape"> </activity> 

<intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 

     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 

<activity 
    android:name="com.example.GamePlay.Game" 
    android:configChanges="orientation|keyboardHidden" 
    android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" 
    android:screenOrientation="landscape" 
    android:label="@string/app_name"></activity> 

SplashScreen.java

public class SplashScreen extends Activity { 
@Override 
public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash_screen); 
    Thread welcomeThread = new Thread() { 
     int wait = 0; 
     @Override 
     public void run() { 
      try { 
       super.run(); 
       while (wait < 2000) { 
        sleep(100); 
        wait += 100;} 
      } catch (Exception e) { 
       System.out.println("SplashScreen()"+e.toString()); 
      } finally { 
       System.out.println("Final statment for run()"); 
      }   }  }; 
    welcomeThread.start(); 
    new AsyncTask<Void, Void, Void>(){ 
      @Override 
      protected Void doInBackground(Void... params) { 
        LayoutInflater inflater = (LayoutInflater)      SplashScreen.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    Game.cachedView = inflater.inflate(R.layout.activity_game, null, false); 
        return null; 
       } 
       @Override 
       protected void onPostExecute(Void aVoid) { 
        finish(); 
        Intent intent = new Intent(getBaseContext(), Game.class); 
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
        startActivity(intent); 
       } 
      }.execute(); 
     }  } 

請幫我解決這個問題。

+1

將意圖過濾器**置於** splash splash清單元素中。 – Luksprog

+0

我會認真地推薦你學習更多關於Android的知識。看看你發佈的代碼和XML,整個事情從一開始就註定要失敗。 – Squonk

回答

1

你應該意圖過濾器後,要關閉活動和第二活動並無意圖過濾器..

<activity 
    android:label="@string/app_name" 
    android:name="com.example.GamePlay.SplashScreen" 
    android:configChanges="orientation|keyboardHidden" 
    android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" 
    android:screenOrientation="landscape"> 

<intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 

<activity 
    android:name="com.example.GamePlay.Game" 
    android:configChanges="orientation|keyboardHidden" 
    android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" 
    android:screenOrientation="landscape" 
    android:label="@string/app_name"> 
<intent-filter> 
     <action android:name="android.intent.action.GAME" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</activity> 
+0

如果有幫助,請接受答案,歡迎來到StackOverFlow! –

+0

我認爲@maria已經是會員7個月了;)。開玩笑。 –

+0

所以它等待2秒,但徽標不出現? –

2

我相信你需要把那個意圖過濾您的活動標籤內。

目前它不與活動相關聯,因此在啓動時不會加載。

<activity 
    android:label="@string/app_name" 
    android:name="com.example.GamePlay.SplashScreen" 
    android:configChanges="orientation|keyboardHidden" 
    android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" 
    android:screenOrientation="landscape"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 
0

基本步驟來顯示啓動: -

1.Desgin你飛濺XML。

2.添加您的splash.java文件。

3.最後在AndroidMainfest文件中調用它。

在Java文件包含意向像這樣: -

public class SplashScreen extends Activity { 
private long splashDelay = 5000; //5 seconds 

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

    TimerTask task = new TimerTask() 
    { 

     @Override 
     public void run() { 
      finish(); 
      Intent mainIntent = new Intent().setClass(SplashScreen.this, SplashActivity.class); 
      startActivity(mainIntent); 
     } 

    }; 

    Timer timer = new Timer(); 
    timer.schedule(task, splashDelay); 
} 
} 
+0

如果有幫助,請接受答案。 – 1999493

0

有時你可以有一個偉大的代碼和問題可能是你使用的IDE。如果在IDE上,例如IntelliJ IDEA,只需將應用程序加載到AVD上(希望它能成功運行 - 但繞過啓動畫面),然後重新加載AVD(或關閉它並再次啓動)。從AVD-do啓動應用程序不要從IDE重新構建它。你會注意到spalshscreen會顯示你設置的延遲時間。 希望這可以幫助你和快樂的Android編碼。 ☺。