Skip to content
Advertisement

React Native Android Splash Screen

I’m trying to build a splash screen for an Android RN app. I’ve followed the steps described here : https://www.bignerdranch.com/blog/splash-screens-the-right-way/

Unfortunately, when trying to launch my app, the build is successful but the app crashes saying:

Error type 3
Error: Activity class {com.needlios/com.needlios.MainActivity} does not exist.

Does any one know where this could come from ?

I have the following code :

SplashScreen.java

package com.needlios;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

MainActivity.java

package com.needlios;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "NeedlIOS";
    }

    /**
     * Returns whether dev mode should be enabled.
     * This enables e.g. the dev menu.
     */
    @Override
    protected boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
    }

   /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
        );
    }
}

AndroidManifest.xml

<activity
  android:name=".SplashActivity"
  android:label="@string/app_name"
  android:theme="@style/SplashTheme">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

Advertisement

Answer

OK, well it works now. I just changed the android:name to android:name=".MainActivity" in AndroidManifest.xml

It works but I don’t understand why it shows the splash screen though…

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement