Search code examples
androidstylessplash-screenoncreate

super.onCreate crashes after defining custom splash screen style to Activity?


I wanted to add a SplashScreen to my app and did a little research on the matter. Some tutorials said that you could create an activity and with some timers show it for a few seconds. I couldn't get them working, and then in this page How do I make a splash screen? the second top voted answer said that instead of showing an activity (and because of that wouldn't substitute the white/black launch loading screen but instead add more delays) you should instead create a custom style and assign it to your activity in the Manifest file. I did that, created a new Style like this:

<style name="splashScreenTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/launchscreen</item>
</style>

in the styles.xml and changed my Manifest to this:

    <application
    android:name=".EFBApp"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivityDrawer"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/splashScreenTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

When I run my app I can see the launch screen perfectly but then it crashes. By breakpoints I discovered that when the MainActivityDrawer (my main class) gets to the super.onCreate(savedInstanceState); line it then crashes (it goes to the ZygoteInit.java class and after that it crashes while breakpoint debugging). If I take away the android:theme lines in the Manifest it works fine but shows the horrible plain white screen while launching. Any suggestions or ideas? Thanks a lot.


Solution

  • Ok, so I managed to make it not crash, instead of assigning the parent as Theme.AppCompat.NoActionBar, I used just AppTheme and it works now. I hope this helps anyone.