incompatible types: MainApplication cannot be converted to Activity
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 :
- Followed README and ran
react-native run-android. The build brakes. - 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);
}
}
Hi, you might want to add the SplashScreen.show(this); in MainActivity.java instead of MainApplication.java.
Just like this:

Hope this helps!
Hi, everyone!
I fix this issue today using a different approach since the fix above didn't worked for me:
Just replace the this inside of the show method for SplashScreen.show((Activity) getContext());
(Activity) getContext()
Thanks that helped a lot. However I add to change the (Activity) to (MainActivity).
Hi, everyone!
I fix this issue today using a different approach since the fix above didn't worked for me:
Just replace the
thisinside of the show method forSplashScreen.show((Activity) getContext());
Didn't work for me. Can you show me that piece of code how did you solve this issue?
(Activity) getContext())
You might want to add import android.app.Activity; to the imports at the top of your MainActivity.java
Sorry the late reply @Red-system! Here follows my MainActivity.java
import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;
import android.app.Activity;
import android.os.Bundle;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
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 "_";
}
/**
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
* you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
* (Paper).
*/
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new MainActivityDelegate(this, getMainComponentName());
}
public static class MainActivityDelegate extends ReactActivityDelegate {
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
super(activity, mainComponentName);
}
@Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}
@Override
protected boolean isConcurrentRootEnabled() {
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show((Activity) getContext());
super.onCreate(savedInstanceState);
}
}
}
+1 same here