MainActivity different from documentation
- React Native version 0.70.6
- Latest "react-native-splash-screen" version
- Android
The code of my MainActivity.java file is different from the one in the docs:
Docs:
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SplashScreenReactPackage() //here
);
}
Mine:
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}
What should I do to add the SplashScreenReactPackage code?
You should add below code:
@Override protected List<ReactPackage> getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List<ReactPackage> packages = new PackageList(this).getPackages(); packages.add(new SplashScreenReactPackage()); return packages; }
The solution above did not work for me, it threw an error when I run the project for android.
I'm using "react-native": "0.70.6", and "react-native-splash-screen": "^3.3.0"
I only had to edit next files:
-
settings.gradle -
build.gradleinside app -
MainActivity.java
No edits inside MainApplication.java were needed for 0.70.6
@Milutin-P How did you change MainActivity.java? because from the version of "react-native": "0.70.6" is different from the documentation
@Milutin-P How did you change MainActivity.java? because from the version of
"react-native": "0.70.6"is different from the documentation
In the MainActivity.java i just included import org.devio.rn.splashscreen.SplashScreen; then with the following
@Override
protected void onCreate(Bundle savedInstanceState){
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
and it works just fine for me in "react-native": "0.71.0",
@ferrero1987 what @samuelhenshaw2020 wrote. I am using "react-native": "0.70.6"
...
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
...
for me "react-native": "0.71.6", "react-native-splash-screen": "^3.3.0",
in MainActivity.java i added
import android.os.Bundle; import org.devio.rn.splashscreen.SplashScreen;
@Override protected ReactActivityDelegate createReactActivityDelegate() { SplashScreen.show(this); //here return new DefaultReactActivityDelegate( this, getMainComponentName(), // If you opted-in for the New Architecture, we enable the Fabric Renderer. DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18). DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled ); } }
for me "react-native": "0.71.6", "react-native-splash-screen": "^3.3.0",
in MainActivity.java i added
import android.os.Bundle; import org.devio.rn.splashscreen.SplashScreen;
@Override protected ReactActivityDelegate createReactActivityDelegate() { SplashScreen.show(this); //here return new DefaultReactActivityDelegate( this, getMainComponentName(), // If you opted-in for the New Architecture, we enable the Fabric Renderer. DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18). DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled ); } }