question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android MyActivity is different from documentation

See original GitHub issue

My MyActivity.java looks like this.

package com.myapp;

import com.facebook.react.ReactActivity;

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 "myapp";
    }
}

if I add

import android.os.Bundle; // here
import com.facebook.react.ReactActivity;
// react-native-splash-screen >= 0.3.1
import org.devio.rn.splashscreen.SplashScreen; // here
// react-native-splash-screen < 0.3.1
import com.cboy.rn.splashscreen.SplashScreen; // here

...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this, true); //https://github.com/crazycodeboy/react-native-splash-screen/issues/167
        super.onCreate(savedInstanceState);
    }

app will crash

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:13

github_iconTop GitHub Comments

11reactions
cayassocommented, Jun 21, 2018

So the key is to add also import android.os.Bundle; as shown bellow 😉

package com.spry;

import android.os.Bundle;
import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;

public class MainActivity extends ReactActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      SplashScreen.show(this);
      super.onCreate(savedInstanceState);
    }

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "myapp";
    }
}
7reactions
fssantoscommented, Feb 24, 2019

I agree docs could be a bit more clear.

Instead of:

Update the MainActivity.java to use react-native-splash-screen via the following changes:

Something like:

Update the MainActivity.java to use react-native-splash-screen via the following changes (it’s yours MainActivity file, not yours MainApplication file. If it doesn’t exist you should insert the onCreate method):

Read more comments on GitHub >

github_iconTop Results From Across the Web

Activity - Android Developers
It is possible if a new non-full-sized or transparent activity has focus on top of your activity, another activity has higher position in...
Read more >
Difference between document activities and regular activities
Document activities allow multiple instances of the same Activity to exist in different tasks, and therefore there will be multiple ...
Read more >
Maps SDK for Android Quickstart - Google Developers
The maps activity file is the main activity for the app, and contains the code to manage and display the map. By default,...
Read more >
Activity vs Fragment in Android - Medium
According to the Android Developer's official documentation, ... Fragments cannot live on their own--they must be hosted by an activity or another fragment....
Read more >
View activity & file versions - Android - Google Drive Help
To restore recent versions of PDF files, images, and other files, go to drive.google.com on a computer. Version history. Version history for Google...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found