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

MainActivity getting destroyed intermittently / App is crashing while opening camera multiple times. #1816

Closed
manishadp opened this issue Jul 10, 2023 · 6 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

@manishadp
Copy link

manishadp commented Jul 10, 2023

Description

For react-native screens, we tried with multiple versions, from 3.17.0 to 3.22.0, but in vain.

In super.onCreate, when we pass savedInstanceState as null (super.onCreate(null)) and open the camera multiple times ( Approximately 10-15 times), MainActivity is getting re-created and the app is re-launching.

If we pass super.onCreate(savedInstanceState) and do the same steps again then i'm getting below issue.

androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenStackFragment: calling Fragment constructor caused an exception
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3834)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3980)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2394)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:211)
at android.os.Looper.loop(Looper.java:300)
at android.app.ActivityThread.main(ActivityThread.java:8296)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenStackFragment: calling Fragment constructor caused an exception
at androidx.fragment.app.Fragment.instantiate(Fragment.java:631)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483)
at androidx.fragment.app.FragmentStateManager.(FragmentStateManager.java:85)
at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2728)
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:198)
at androidx.fragment.app.FragmentActivity$2.onContextAvailable(FragmentActivity.java:149)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:362)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:45)
at com.adp.time.kiosk.MainActivity.onCreate(MainActivity.java:70)
at android.app.Activity.performCreate(Activity.java:8523)
at android.app.Activity.performCreate(Activity.java:8487)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1438)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3815)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3980) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2394) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:211) 
at android.os.Looper.loop(Looper.java:300) 
at android.app.ActivityThread.main(ActivityThread.java:8296) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:613)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57) 
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483) 
at androidx.fragment.app.FragmentStateManager.(FragmentStateManager.java:85) 
at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2728) 
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:198) 
at androidx.fragment.app.FragmentActivity$2.onContextAvailable(FragmentActivity.java:149) 
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99) 
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:362) 
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273) 
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:45) 
at com.adp.time.kiosk.MainActivity.onCreate(MainActivity.java:70) 
at android.app.Activity.performCreate(Activity.java:8523) 
at android.app.Activity.performCreate(Activity.java:8487) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1438) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3815) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3980) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2394) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:211) 
at android.os.Looper.loop(Looper.java:300) 
at android.app.ActivityThread.main(ActivityThread.java:8296) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954) 
Caused by: java.lang.IllegalStateException: Screen fragments should never be restored. Follow instructions from #17 (comment) to properly configure your main activity.

Steps to reproduce

  1. Open camera.
  2. Close camera.
  3. Do the above steps repeatedly (opening and closing the camera).

Snack or a link to a repository

https://stackoverflow.com/questions/57709742/unable-to-instantiate-fragment-com-swmansion-rnscreens-screen

Screens version

3.22.0

React Native version

0.70.6

Platforms

Android

JavaScript runtime

JSC

Workflow

None

Architecture

None

Build type

None

Device

Real device

Device model

All devices

Acknowledgements

Yes

@github-actions github-actions bot added Platform: Android This issue is specific to Android Missing repro This issue need minimum repro scenario labels Jul 10, 2023
@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?

@jullapas
Copy link

jullapas commented Jul 10, 2023

I too had the same issue and the same steps have to be followed in my case too.

Followed the solutions provided in the following links but none of them are really solving my issue.

#1481

#17

https://stackoverflow.com/questions/57709742/unable-to-instantiate-fragment-com-swmansion-rnscreens-screen

We stopped a Production release because of this. Can someone please help us on this ?

@tboba
Copy link
Member

tboba commented Jul 12, 2023

Hi @manishadp, thanks for the feedback! Could you provide us a link to the repository with code where the problem occurs, so we could reproduce the problem with provided steps?

@manishadp
Copy link
Author

Unfortunately we work for an organisation and we are not allowed to share the code. Just adding some more info - This is basically happening when we are trying to open and close the camera repeatedly multiple times.

@manishadp
Copy link
Author

manishadp commented Jul 17, 2023

Hi @tboba , It would be really grateful if you can respond faster as we are blocked from pushing the app to production.

I found there is memory leaks, I'm adding screen shot. ScreenFragment and ScreenStackFragment I'm getting exception in both classes. Could you please check once.

To reproduce the issue which i'm facing , you need to go to developer option and go to APPS and turn on Don't keep Activities
and run any react-naive app . you will get the same issues. and i'm adding the snapshot.

constructor() {
Screenshot 2023-07-17 at 8 10 13 PM

    throw IllegalStateException(
        "ScreenStack fragments should never be restored. Follow instructions from https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067 to properly configure your main activity."
    )
}
Screenshot 2023-07-17 at 6 20 37 PM

@tsapeta
Copy link
Member

tsapeta commented Jul 18, 2023

Hi @manishadp,

Taking into account that a minimal reproducible example was not provided and we are not able to reproduce it on our side, we cannot prioritize your issue over other issues where such an example has been provided. As the library is open source, you can always try to fix the problem yourself (especially that you are able to reproduce it).

Our libraries are maintained free of charge by a team with a limited number of people involved, but if you are not happy with the current pace of development and need premium support dedicated for your app, please reach out to us by sending an email to contact@swmansion.com.

@tsapeta tsapeta added the Close when stale This issue is going to be closed when there is no activity for a while label Jul 18, 2023
@github-actions github-actions bot closed this as completed Aug 7, 2023
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

4 participants