React-native-splash-screen: MainActivity

Created on 9 May 2018  路  5Comments  路  Source: crazycodeboy/react-native-splash-screen

Why My Andorid does not has a onCreate method inthe MainActivity?

Most helpful comment

Working example of MainActivity.java

package com.myapp
import android.os.Bundle;
import com.facebook.react.ReactActivity;
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);  // here
        super.onCreate(savedInstanceState);
    }
    @Override
    protected String getMainComponentName() {
        return "myapp";
    }
}

All 5 comments

@ijry I believe you should add this yourself.
Mine did not have an onCreate method either but, following the installation guide:

...
import org.devio.rn.splashscreen.SplashScreen; // import this
import android.os.Bundle; // import this

public class MainActivity extends ReactActivity {

    // I added this method myself
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this);
        super.onCreate(savedInstanceState);
    }

    ...

I am also having this issue. I have tried adding onCreate() myself. I tried removing onNewIntent() method and keeping both but neither worked.

I dont have this code too.
And app is not launching if I add this code.

Working example of MainActivity.java

package com.myapp
import android.os.Bundle;
import com.facebook.react.ReactActivity;
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);  // here
        super.onCreate(savedInstanceState);
    }
    @Override
    protected String getMainComponentName() {
        return "myapp";
    }
}

So the key is to add import android.os.Bundle; as shown above ;-)

Was this page helpful?
0 / 5 - 0 ratings