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.

MainActivityDelegate cannot be converted to Activity SplashScreen.show(this);

See original GitHub issue

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

  • Node : 16.17.0
  • Yarn : 1.22.19
  • react : 18.1.0
  • react-native : 0.70.0

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

  • “react-native-splash-screen”: “^3.3.0”, What platform does your issue occur on? (Android/iOS/Both)
  • just checked Android only.

Describe your issue as precisely as possible :

  1. Steps to reproduce the issue or to explain in which case you get the issue

  2. Interesting logs

error: incompatible types: MainActivityDelegate cannot be converted to Activity
      SplashScreen.show(this);

more details of error

BUILD FAILED in 12s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/minjiseo/buyaladdin/BRApp/BuyaladdinApp/android/app/src/main/java/com/aladdin/com/aladdin/MainActivity.java:59: error: incompatible types: MainActivityDelegate cannot be converted to Activity
      SplashScreen.show(this);
                        ^
Note: /Users/minjiseo/myFolder/MyAppName/AppName/android/app/src/debug/java/com/AppName/com/AppName/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

Join a screenshot or video of the problem on the simulator or device?

Show us the code you are using?

followed the guide settings.gradle, build.gradle, App.tsx and set all done.

MainActivity.java

package com.aladdin.com.aladdin;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.lockincomp.liappagent.LiappAgent;

import org.devio.rn.splashscreen.SplashScreen;
...
@Override
    protected void onCreate(Bundle savedInstanceState) {

      SplashScreen.show(this);
  
     ...my other codes

      super.onCreate(null);
// super.onCreate(savedInstanceState); <- this also tried but not working
    }

I don’t know why I’m having this kind of error. because of React Native 0.7 version error? or what,please help…

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12

github_iconTop GitHub Comments

3reactions
bonusrkcommented, Nov 7, 2022

@bonusrk I followed your guide, but mine doesn’t work.

package com.myapp.com.myapp;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.lockincomp.liappagent.LiappAgent;

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

  /**
   * 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.    //<-------here is I added onCreate upper side but still doesn't work...is that right way I did?
  protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);
    super.onCreate(null);
  }


  @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) {

      ...my other codes which supposed to in this area
      super.onCreate(null);
    }
  }
}

I think you should move onCreate totally. I mean delete it in nested class and keep only in top level. I went event a little bit forward and kept only main class just to check and it works

package com.myapp;

import android.os.Bundle;
import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;
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 "MyApp";
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);
    super.onCreate(null);
  }
}
3reactions
bonusrkcommented, Nov 8, 2022

Fresh RN application MainActivity.java looks like so now:

package com.myapp;

import android.os.Bundle;
import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;
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 "MyApp";
  }

  /**
   * 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(this);
      super.onCreate(null);
    }
  }
}

Still have the issue incompatible types: MainActivityDelegate cannot be converted to Activity SplashScreen.show(this);

method show goes from here

    /**
     * 打开启动屏
     */
    public static void show(final Activity activity) {
        show(activity, false);
    }

and it take Activity type, while this in MainActivity is MainActivityDelegate

If we move onCreate outside of MainActivityDelegate to the very top class application will be built successfully

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - MainActivityDelegate cannot be converted to ...
Error. MainActivityDelegate cannot be converted to Activity SplashScreen.show(this);. MainActivity.java. ` package com.ala.
Read more >
MainApplication cannot be converted to Activity · Issue #461 ...
Hi, you might want to add the SplashScreen.show(this); in MainActivity.java instead of MainApplication.java . Just like this: Screen Shot 2020- ...
Read more >
Splash Screen in Android App — React Native
Step 1: Create an activity. Create a new activity which will be responsible for forwarding to main activity. In android/app/src/main/java/[packageName] create ...
Read more >
How to integrate a splash screen in React Native with ...
In this shot, we will learn how to integrate splash screens in React Native for both Android and iOS. Installation. First, let's create...
Read more >
react-native-splash-screen - npm
A splash screen API for react-native which can programatically hide and show the splash screen. Works on iOS and Android.
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