You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Android:MainActivity继承两个类的冲突解决求助

How to Resolve Conflict Between react-native-splash-screen and react-native-navigation's SplashActivity

Hey there! I’ve dealt with this exact conflict before when combining these two libraries, so let me break down the easiest ways to fix it—no deep Java expertise required.

Since you’re already extending SplashActivity from react-native-navigation, it’s simpler to ditch react-native-splash-screen entirely and use RNN’s native splash screen support. This eliminates the dependency conflict and keeps your setup cleaner.

Here’s how to set it up:

  • First, uninstall react-native-splash-screen if you’ve already added it:
    npm uninstall react-native-splash-screen
    # Or yarn remove react-native-splash-screen
    
  • Remove any react-native-splash-screen related config from your Android project (like the SplashScreenActivity entry in AndroidManifest.xml and any splash drawables you added for it).
  • Create your splash screen drawable (a splash_bg.xml or PNG file) in android/app/src/main/res/drawable.
  • Update your AndroidManifest.xml to use a custom theme for your MainActivity:
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
  • Add the SplashTheme to android/app/src/main/res/values/styles.xml:
    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_bg</item>
        <!-- Optional: Set your status bar color -->
        <item name="android:statusBarColor">@color/your_preferred_color</item>
    </style>
    

That’s it! RNN will automatically show this splash screen until your React Native app is ready to render.

Option 2: Keep Using react-native-splash-screen With RNN

If you really need to stick with react-native-splash-screen, you can still make it work without multi-inheritance. RNN’s SplashActivity handles the React Native initialization under the hood, so you just need to call the splash screen method in its lifecycle.

Here’s the modified MainActivity.java:

import com.reactnativenavigation.controllers.SplashActivity;
import org.devio.rn.splashscreen.SplashScreen;
import android.os.Bundle;

public class MainActivity extends SplashActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Show the react-native-splash-screen before calling super.onCreate
        SplashScreen.show(this);
        super.onCreate(savedInstanceState);
    }
}

Then, in your React Native JavaScript code, call SplashScreen.hide() once your app is fully loaded (just like you would normally with react-native-splash-screen).

Why This Works

RNN’s SplashActivity is already built to bootstrap your React Native app, so you don’t need to extend ReactActivity directly. By adding SplashScreen.show(this) in the onCreate method, you’re just injecting the splash screen logic into RNN’s existing initialization flow.

内容的提问来源于stack exchange,提问作者jpls93

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:02:40