【问题标题】:MainActivityDelegate cannot be converted to Activity SplashScreen.show(this);MainActivityDelegate 无法转换为 Activity SplashScreen.show(this);
【发布时间】:2022-11-07 17:15:21
【问题描述】:

我在使用 react-native-splash-screen 时遇到问题

反应原生信息

  • 节点:16.17.0
  • 纱线:1.22.19
  • 反应:18.1.0
  • 反应原生:0.70.0

错误

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

MainActivity.java

`

package com.ala.com.ala;

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
}

`

我不知道为什么我会出现这种错误。因为 React Native 0.7 版本错误?或者什么...请帮助..

我也尝试使用 react-native-bootsplash 但是这个库也有错误

`@覆盖
protected void onCreate(Bundle savedInstanceState) {

RNBootSplash.init(this); //这部分有错误
super.onCreate(savedInstanceState); // 或带有 react-native-screens 的 super.onCreate(null)
}`

【问题讨论】:

    标签: react-native react-native-splash-screen


    【解决方案1】:
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
     ...my other codes
    
         super.onCreate(null);
       //super.onCreate(savedInstanceState); <- this also tried but not working
    
         SplashScreen.show(this);
    
         
      }
    

    试试这个,还从 setting.gradle 和 app/build.gradle 文件中删除其他手动配置以用于启动画面。希望这会奏效。

    【讨论】:

      【解决方案2】:

      如果你们在 RN 版本上有同样的问题。 0.7 使用 react-native-splash-screen,请检查这个

      https://github.com/crazycodeboy/react-native-splash-screen/issues/591#issue-1424947030

      我解决了我的问题

      【讨论】:

        猜你喜欢
        • 2018-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-04
        相关资源
        最近更新 更多