How to change starting intent React Native

Viewed 1213

I'm using an open source code to develop an Android app, using React Native. I've added a Splash Screen (SplashActivity.java) and kept it as the launcher in AndroidManifest.xml. However, everytime I run the app, the terminal shows the following output:

BUILD SUCCESSFUL in 30s
266 actionable tasks: 12 executed, 254 up-to-date
info Connecting to the development server...
info Starting the app on "MYDEVICE"...
Starting: Intent { cmp=go.sampleproject.io/.MainActivity }

The last line shows that the starting intent is MainActivity. Can anyone suggest how that can be changed to SplashActivity instead?

The code runs properly, but when I run the app through the terminal, my device does not display the SplashActivity even though I have kept it as the launcher in my AndroidManifest.xml.

2 Answers

I know it is little to late, but I made it like this:

  1. Changed name of MainActivity to AppActivity (file + class)
  2. Changed name of SplashActivity to MainActivity (file + class)
  3. Changed names in XML files accordingly

Now it works as expected.

for android, the react-native starts firstly the action is MAIN activity, you can config it, it means you can modify the activity. in the main activity, you can config the main component, which is registered in the index.js

<activity
        android:name=".MainActivity"


        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
        </intent-filter>
    </activity>

  // Main Activity config the firstly start component
  @Override
  protected String getMainComponentName() {
    return "MainComponent";
  }

 // in the rn index.js
 import { AppRegistry } from 'react-native';
 import App from './App';
 AppRegistry.registerComponent('MainComponent', () => App);

like the below code, you can config the which activity to start, which component is the main component.

As for intent and activity, activity is the ui which showed for user, the intent is the common way to start activity, you can read the official Api

if you want to start another activity, you have to write a bridge module, define a method to start activity, then import it in the component where you use. the detail about bridge module you can go to the react-native official site native modules for android

public class UtilModule extends ReactContextBaseJavaModule {


private static Activity ma;


public UtilModule(ReactApplicationContext reactContext) {
    super(reactContext);
}


public static void initUtilModule(MainActivity activity) {
    ma = activity;
}

@Override
public String getName() {
    return "UtilModule";
}

Related