简体   繁体   中英

Splash Screen making app crash

I added splash screen to my application however it make my app crash. Here's the thing the Splash Screen is showing however it doesn't start my MainActivity. Help guys. See my Manifest..

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity android:name=".Splash">
        <intent-filter>
            <action android:name="com.example.billeazy.SPLASH" />

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

Your "Splash" activity need to be MAIN LAUNCHER Activity. So modify the AndroidManifest file like this...

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
    </activity>

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

And Jump to MainActivity after few seconds..

Handler hadler=new Handler();
        hadler.postDelayed(new Runnable() {
            @Override
            public void run () {
                finish();
                Intent i = new Intent(context, MainActivity.class);
                startActivity(i);
            }
        }, 3000);

here 3000 is used for 3 seconds. The MainActivity auto start after 3 seconds. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM