1

I am trying to create two splash screens in Android studio. My first splash screen works fine but my second splash screen does not.

How can I create a second splash screen?

Here is My code for the first splash screen below:

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>

Layout code

<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>
emrekose26
  • 683
  • 1
  • 8
  • 21

1 Answers1

1

Create a new splash activity now, instead of doing an intent to MainActivty in the first splash intent to the second splash and finally intent to MainActivity from the second splash.

The code for the second splash is identical to the one you already have.

nishon.tan
  • 969
  • 2
  • 8
  • 21
  • I am on my phone! tell me if you don't understand something – nishon.tan Nov 19 '16 at 17:23
  • I have already tried this and my app crashes after the first splash screen. try { sleep(3000); Intent startMainScreen = new Intent(getApplicationContext(), SplasScreen2.class); startActivity(startMainScreen); finish(); } catch (InterruptedException e) { e.printStackTrace(); } – Lyubomir Ivanov Valchev Nov 19 '16 at 17:28
  • 1
    I do not get an error log. It tells me Unfortunately App_Name has stopped. Unless the error logs are somewhere else where I can't see them. Sorry I am a little new to Android studio – Lyubomir Ivanov Valchev Nov 19 '16 at 17:34
  • java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lyubo.clubscene/com.example.lyubo.clubscene.SplasScreen2}: android.view.InflateException: Binary XML file line #2: Error inflating class Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class – Lyubomir Ivanov Valchev Nov 19 '16 at 17:38
  • is there a reason for inheriting MainActiviyy – nishon.tan Nov 19 '16 at 17:45
  • I fixed the problem. The problem was that one of my images was too large – Lyubomir Ivanov Valchev Nov 19 '16 at 21:28