ReactNative combined with native Intent page jump value transfer problem

problem description

after the native class jumps to the RN class, the Intent object is null

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)
Native classes

public class MainActivity extends Activity {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

}

public  void onClick(View v){
    Intent in=new Intent(this,SecondActivity.class);
    in.putExtra("name","Test");
    in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(in);
}

}

inherits ReactActivity"s class
public class SecondActivity extends ReactActivity {

@Override
protected String getMainComponentName() {
    String str = "Test";
    Intent intent = getIntent();
    if (intent != null) {
        str = intent.getStringExtra("name");
        Log.e("SecondActivity", "SecondActivity" + str);
    }
    return str;
}

}

what result do you expect? What is the error message actually seen?

Jun.01,2021

you can declare a static variable directly in the SecondActivity class without Intent, and then modify the value of the static variable in the SecondActivity class before executing the startActivity method in the MainActivity class, and then you'll be fine

.
Menu