react-native-splash-screen icon indicating copy to clipboard operation
react-native-splash-screen copied to clipboard

onCreate method does not exist in MainActivity.java

Open mahdi-rafiei opened this issue 3 years ago • 7 comments

The onCreate method does not exists in MainActivity.java and after creating it as described in documentation, the app wont open and crashes.

What I'm using: "react-native": "0.66.4", "react-native-splash-screen": "^3.3.0",

The Platform: Android

`package com.app;

import android.os.Bundle; import com.facebook.react.ReactActivity;

// react-native-splash-screen >= 0.3.1 import org.devio.rn.splashscreen.SplashScreen;

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 void onCreate(Bundle savedInstanceState) { SplashScreen.show(this); // rn splash screen

    super.onCreate(savedInstanceState); }

@Override protected String getMainComponentName() { return "Admin"; } }`

mahdi-rafiei avatar Feb 04 '22 14:02 mahdi-rafiei

Also experiencing this in react-native 0.67.2.

alexgermann avatar Feb 14 '22 21:02 alexgermann

dont know if it will fix your problem but its worth a try. but react-native-screens and react-navigation recommend passing "null" instead of "savedInstanceState" to the onCreate() method. see:

https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067 https://github.com/software-mansion/react-native-screens#android https://reactnavigation.org/docs/getting-started/#installing-dependencies-into-a-bare-react-native-project (v6)

Adnan-Bacic avatar Mar 14 '22 14:03 Adnan-Bacic

please add this line in MainActivvity.java

import android.os.Bundle;

kameshkumar786 avatar Mar 19 '22 13:03 kameshkumar786

Had this same problem and @kameshkumar786 's tip did the trick. Thank you!

mbckhs avatar May 13 '22 20:05 mbckhs

Had the same issue, followed this and fixed it https://github.com/crazycodeboy/react-native-splash-screen/issues/167#issuecomment-517971996

vasscher avatar Jun 01 '22 14:06 vasscher

After creating an splash image through react-native-make, onCreate method will be created.

jmk5315 avatar Aug 29 '22 05:08 jmk5315

Save my life @kameshkumar786 ! Show!!!! Work for me: import android.os.Bundle;

waslinux avatar Oct 13 '22 14:10 waslinux

if importing import android.os.Bundle doesn't help (because in a fresh-generated RN app it is already there) you can try this #591(comment) TLDR - onCreate method placed in the nested class, where this points to the entity of a different type, not that SplashScreen.show awaits. But if move onCreate to the top level class in MainActivity file, everything seems to work.

bonusrk avatar Nov 08 '22 08:11 bonusrk

import android.os.Bundle;

inside the Activity class @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... }

Osmon11 avatar Oct 29 '23 09:10 Osmon11