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 when reopen app from background after memory cleaned up #32717

Closed
rnike opened this issue Dec 7, 2021 · 6 comments
Closed

[Android] Crash when reopen app from background after memory cleaned up #32717

rnike opened this issue Dec 7, 2021 · 6 comments
Labels
Needs: Triage 🔍 Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@rnike
Copy link
Contributor

rnike commented Dec 7, 2021

Description

Facing an issue, the app crash after the memory is cleaned up on Android, seems like the app will eventually crash if the user sends it to the background for a while after the android system recycles the memory usage.

here's the error msg

12-07 10:06:44.946  1696  1696 E AndroidRuntime: FATAL EXCEPTION: main
12-07 10:06:44.946  1696  1696 E AndroidRuntime: Process: tw.com.myapp, PID: 1696
12-07 10:06:44.946  1696  1696 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{tw.com.myapp/tw.com.myapp.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment: calling Fragment constructor caused an exception
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3116)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3259)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1950)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:214)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7073)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment: calling Fragment constructor caused an exception
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.Fragment.instantiate(Fragment.java:628)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.FragmentStateManager.<init>(FragmentStateManager.java:85)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2714)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:198)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.FragmentActivity$2.onContextAvailable(FragmentActivity.java:149)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:307)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:269)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:115)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:45)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at tw.com.myapp.MainActivity.onCreate(MainActivity.java:39)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:7327)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:7318)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3096)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	... 11 more
12-07 10:06:44.946  1696  1696 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at java.lang.reflect.Constructor.newInstance0(Native Method)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at androidx.fragment.app.Fragment.instantiate(Fragment.java:610)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	... 27 more
12-07 10:06:44.946  1696  1696 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Screen 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.
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	at com.swmansion.rnscreens.ScreenFragment.<init>(ScreenFragment.kt:41)
12-07 10:06:44.946  1696  1696 E AndroidRuntime: 	... 30 more

It crashed on super.onCreate(savedInstanceState); in MainActivity.java, I assume it is a react-native issue.

Version

0.66.2

Output of react-native info

System:
OS: macOS 11.5.1
CPU: (4) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Memory: 136.54 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.22.6 - /var/folders/g2/xnd8hpjs50v433gfrybz2nxh0000gn/T/yarn--1638849014786-0.026624988105482972/node
Yarn: 1.22.11 - /var/folders/g2/xnd8hpjs50v433gfrybz2nxh0000gn/T/yarn--1638849014786-0.026624988105482972/yarn
npm: 6.14.15 - /usr/local/bin/npm
Watchman: 2021.08.30.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.2 - /Users/vagrant/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
Android SDK:
API Levels: 15, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
Build Tools: 19.1.0, 21.1.2, 22.0.1, 23.0.3, 24.0.3, 25.0.3, 26.0.1, 26.0.2, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.1, 28.0.2, 28.0.3, 29.0.0, 29.0.1, 29.0.2, 29.0.3, 30.0.0, 30.0.1, 30.0.2, 30.0.3
System Images: android-26 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
Android NDK: 21.4.7075529
IDEs:
Android Studio: Not Found
Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /Users/vagrant/.jenv/shims/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: ^0.66.2 => 0.66.2
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  1. install and start the app
  2. move app to background
  3. clean device memory
  4. reopen the app and it will crash on startup

Snack, code example, screenshot, or link to a repository

No response

@rnike
Copy link
Contributor Author

rnike commented Dec 7, 2021

Found out it was an issue related to react-native-screens not react-native, I've missed the solution in the error log

12-07 10:06:44.946  1696  1696 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Screen 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.

Apply the solution this error is no longer exists, the issue can be closed.

@rnike rnike closed this as completed Dec 7, 2021
@rishiankush
Copy link

This work around is already added when you use react native latest versions. It still does not help at least for me.

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

Did not work out for me. it was already there for react native version 0.64.2 which I am using currently

@rassemdev
Copy link

I am also facing this problem and using RN: 0.64.2, But i am not seeing this code on mu MainActivity.java class,

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

Where are you referring it at?

@AhmetToma
Copy link

Im still facing this issue i have tried almost every thing
Please help

@karatekid430
Copy link

Overriding onCreate is not a solution as this prevents deep linking from working.

@subhadeepquantiantech

This comment was marked as off-topic.

@facebook facebook locked as resolved and limited conversation to collaborators Dec 7, 2022
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Dec 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Triage 🔍 Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants