2016-11-19 54 views
0

我想在Android工作室中創建兩個啓動畫面。我的第一個啓動畫面工作正常,但我的第二個啓動畫面沒有。Android工作室中的多個啓動畫面

如何創建第二個啓動畫面?

這裏是我下面的第一個啓動畫面代碼:

MainActivity.java

public class SplashScreen extends MainActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 
    Thread myThread = new Thread(){ 
     @Override 
     public void run() { 
      try { 
       sleep(3000); 
       Intent startMainScreen = new Intent(getApplicationContext(), MainActivity.class); 
       startActivity(startMainScreen); 
       finish(); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 

     } 
    }; 
    getSupportActionBar().hide(); 
    myThread.start(); 
} 

}

AndroidManifest.xml中

<activity android:name=".SplashScreen"> 

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

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

</activity> 

佈局代碼

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_collapseParallaxMultiplier="1.0" 
    android:weightSum="1" 
    android:background="@drawable/cls2"> 
</LinearLayout> 
+0

你能給我多一點細節嗎? – emrekose26

+0

我想在第一個屏幕消失後立即查看另一個啓動屏幕 –

+0

第二個屏幕是主屏幕還是會關閉並打開另一個屏幕? – emrekose26

回答

2

創建一個新的飛濺活動 現在,而不是在第一飛濺的意圖做的意圖MainActivty 到第二飛濺 終於從第二飛濺意圖MainActivity。

第二次飛濺的代碼與您已有的代碼完全相同。

+0

我正在使用我的手機!告訴我,如果你不明白的東西 –

+0

我已經試過這個,我的應用程序在第一次啓動屏幕後崩潰。 try { sleep(3000); Intent startMainScreen = new Intent(getApplicationContext(),SplasScreen2.class); startActivity(startMainScreen); finish(); (InterruptedException e){ e.printStackTrace(); } –

+0

您好,我想查看您的錯誤日誌 –