Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android crash: "Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment #1697

Closed
swiggyrahulgupta5 opened this issue Jan 27, 2023 · 10 comments
Labels
Close when stale This issue is going to be closed when there is no activity for a while Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android

Comments

@swiggyrahulgupta5
Copy link

Description

I am react-native-screens in my application.
My app is a tab bar with 5 fragments one of which is a react native module and 1 tab is an activity with a react native module as well.
When i open the fragment with the react native code,
then open the activty and navigate back and forth between these two, i get this crash:

AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app/com.app.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment: calling Fragment constructor caused an exception

Fragment A (React Native) has Activity A as a parent
Activity B(React Native)
So there are two different things here (mind my english) but then how is this causing this ScreenFragment issue?
Is ScreenFragment singleton?
Please advice how can i keep separate instances of react native navigation if i have 2 different react native components one is loaded in a fragment and one in an activity in the same app

Steps to reproduce

Create a Fragment with react native screens
Create an activity with react native screens
Navigate back and forth between these two will cause this crash

Snack or a link to a repository

https://stackoverflow.com/help/mcve

Screens version

3.8.0

React Native version

0.69.0

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

None

Device

Android emulator

Device model

No response

Acknowledgements

Yes

@github-actions
Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@github-actions github-actions bot added Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android labels Jan 27, 2023
@kkafar
Copy link
Member

kkafar commented Jan 27, 2023

Hey @swiggyrahulgupta5,
first thing to try is testing out more recent react-native-screens version.
Besides that providing a repo with reproduction would be of massive value to help resolve this issue.

@kkafar kkafar added the Close when stale This issue is going to be closed when there is no activity for a while label Jan 27, 2023
@adnansudozai
Copy link

adnansudozai commented Aug 28, 2023

@swiggyrahulgupta5 Have you solved the issue? I have also face this issue to on Samsung devices

@gkasireddy202
Copy link

Facing same issue on react-native:0.73.7

@mostafahpater
Copy link

mostafahpater commented Sep 2, 2024

Add this to your MainActivity.java if you are using java in your react native

import android.os.Bundle;
@ Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
}

or add this to your MainActivity.kt if you are using Kotlin in your react native

import android.os.Bundle
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(null)
}

@gkasireddy202
Copy link

@mostafahpater - Thanks for your reply.
Can I add the code in the below file path right?
import android.os.Bundle
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(null)
}

Appname>android>app>src>main>java>com>MyApp>MainActvity.kt

@mostafahpater
Copy link

@gkasireddy202
yes this is path of file and add import up of page and add fun inside (class MainActivity )

@FaithChinonso
Copy link

@mostafahpater - Thanks for your reply. Can I add the code in the below file path right? import android.os.Bundle override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(null) }

Appname>android>app>src>main>java>com>MyApp>MainActvity.kt

did this work for you?

@gkasireddy202
Copy link

I tested this fix on Pixel 8 and did not face this issue on Pixel 8.

@Andreibv
Copy link

Add this to your MainActivity.java if you are using java in your react native

import android.os.Bundle; @ Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(null); }

or add this to your MainActivity.kt if you are using Kotlin in your react native

import android.os.Bundle override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(null) }

Let me try with this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Close when stale This issue is going to be closed when there is no activity for a while Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android
Projects
None yet
Development

No branches or pull requests

7 participants