Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 213
G. Hamaide Avatar asked Feb 11 '16 12:02

G. Hamaide


2 Answers

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...

like image 62
G. Hamaide Avatar answered Sep 16 '22 16:09

G. Hamaide


Just to share as I got this working too.

The change of the

android:name

to

android:name=".MainActivity" in AndroidManifest.xml

is working because the whole background has been modified to Splashscreen theme. It might not be a good solution, as if the backgroundColor is removed from any screens; this splash screen background will appear. Eventually it'll lead to some unwanted displays when you need to integrate with some camera features. :(

Most of the codes are based on this link with just splash activity removed. If anyone is searching do add values/colors.xml and drawable/backgroundsplash.xml.

like image 36
Han Avatar answered Sep 19 '22 16:09

Han