React-native-splash-screen: incompatible types: MainApplication cannot be converted to Activity

Created on 19 Feb 2020  路  1Comment  路  Source: crazycodeboy/react-native-splash-screen

Run react-native info in your project and share the content.

System:
    OS: macOS 10.15.3
    CPU: (4) x64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
    Memory: 310.18 MB / 24.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 13.3.0 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 22, 23, 24, 25, 26, 27, 28, 29
      Build Tools: 23.0.1, 26.0.1, 26.0.2, 27.0.3, 28.0.3, 29.0.1, 29.0.2, 29.0.3
      System Images: android-26 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: 20.0.5594570
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  npmPackages:
    @react-native-community/cli: ^2.9.0 => 2.10.0 
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.1 => 0.61.1 
  npmGlobalPackages:
    create-react-native-app: 1.0.0
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7
    react-native-macos-cli: 2.0.1
    react-native-scripts: 1.8.1

What react-native-splash-screen version are you using?
^3.2.0

What platform does your issue occur on? (Android/iOS/Both)
Android

Describe your issue as precisely as possible :
1) Followed README and ran react-native run-android. The build brakes.
2) Error message: incompatible types: MainApplication cannot be converted to Activity

Show us the code you are using?
My MainApplication.java:

import android.app.Application
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.facebook.react.PackageList;
import com.calendarevents.CalendarEventsPackage;
import org.devio.rn.splashscreen.SplashScreen;

import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // additional non auto detected packages can still be added here:
      new CalendarEventsPackage();
      // packages.add(new SomeReactNativePackage());
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    SplashScreen.show(this);
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

Most helpful comment

Hi, you might want to add the SplashScreen.show(this); in MainActivity.java instead of MainApplication.java.
Just like this:
Screen Shot 2020-02-19 at 19 01 21

Hope this helps!

>All comments

Hi, you might want to add the SplashScreen.show(this); in MainActivity.java instead of MainApplication.java.
Just like this:
Screen Shot 2020-02-19 at 19 01 21

Hope this helps!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhaogao picture zhaogao  路  4Comments

mharrisweb picture mharrisweb  路  3Comments

js1121302139 picture js1121302139  路  5Comments

erdemildiz picture erdemildiz  路  5Comments

jetre219 picture jetre219  路  4Comments