[HOLD for payment 2022-01-19] Android - App crashes when entering split screen mode - Reported by: @kakajann
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
- Open the app in a Android device
- Press and hold the recents button in the nav bar to activate splitscreen mode
Expected Result:
App should not crash when entering splitscreen mode.
Actual Result:
App is crashing when entering splitscreen mode.
Workaround:
Unable to use splitscreen mode
Platform:
Where is this issue occurring?
- Android
Version Number: 1.1.17-0
Reproducible in staging?: Yes Reproducible in production?: Yes
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
https://user-images.githubusercontent.com/44479856/144880930-68487b29-8cf0-43ea-99de-f5970f03f6e6.mp4
Expensify/Expensify Issue URL:
Issue reported by: @kakajann Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1638509082167300
Triggered auto assignment to @TomatoToaster (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Hmm, no reason this can't be external so I'm marking at as such.
Triggered auto assignment to @dylanexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
Hi, I have successfully reproduced the crash and manged to grab relevant trace:
12-06 22:29:44.485 12630 12630 E AndroidRuntime: FATAL EXCEPTION: main
12-06 22:29:44.485 12630 12630 E AndroidRuntime: Process: com.expensify.chat, PID: 12630
12-06 22:29:44.485 12630 12630 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.expensify.chat/com.expensify.chat.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment: calling Fragment constructor caused an exception
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7356)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment: calling Fragment constructor caused an exception
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at androidx.fragment.app.Fragment.instantiate(Fragment.java:631)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at androidx.fragment.app.FragmentStateManager.<init>(FragmentStateManager.java:85)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2728)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:1
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: ... 13 more
12-06 22:29:44.485 12630 12630 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at java.lang.reflect.Constructor.newInstance0(Native Method)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: at androidx.fragment.app.Fragment.instantiate(Fragment.java:613)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: ... 28 more
12-06 22:29:44.485 12630 12630 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-06 22:29:44.485 12630 12630 E AndroidRuntime: at com.swmansion.rnscreens.ScreenFragment.<init>(ScreenFragment.java:42)
12-06 22:29:44.485 12630 12630 E AndroidRuntime: ... 31 more
It's actually kinda funny, but in that trace there is a line with a link to a github issue with a solution:
12-06 22:29:44.485 12630 12630 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.
Applying the fix in the linked comment solved the issue and I can no longer reproduce the crash.
Here is the diff:
diff --git a/android/app/src/main/java/com/expensify/chat/MainActivity.java b/android/app/src/main/java/com/expensify/chat/MainActivity.java
index de62c20ea..7a613e277 100644
--- a/android/app/src/main/java/com/expensify/chat/MainActivity.java
+++ b/android/app/src/main/java/com/expensify/chat/MainActivity.java
@@ -17,7 +17,7 @@ public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ super.onCreate(null);
RNBootSplash.init(R.drawable.bootsplash, MainActivity.this); // <- display the generated bootsplash.xml drawable over our MainActivity
}
}
And a demo video with the fix applied.
https://user-images.githubusercontent.com/64093836/144912648-0f759f31-df14-4cfe-b8aa-904141e78c0d.mp4
EDIT: Added a video.
Getting this posted now!
Internal: https://www.upwork.com/ab/applicants/1468220241862590464/job-details External: https://www.upwork.com/jobs/~011ff1a3ecd33bee08
Triggered auto assignment to @parasharrajat (Exported)
Triggered auto assignment to @thienlnam (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@dylanexpensify
If we do following change in androidManifest.xml then problem will be resolved.

@hiteshagja could you please explain your proposal?
- What are you changing in the mean on behaviour?
@parasharrajat What I proposed is that if we add new keys (as shown in screenshot posted earlier) for andoird:configChanges the problem resolves. App does not crash in split screen mode after this change.
What I proposed is that if we add new keys (as shown in screenshot posted earlier) for andoird:configChanges the problem resolves
~I can already see that you proposed a solution and thus it must be fixing the issue~ That sounded rude, Sorry. I meant to ask what does it change in the App so that crash does not happen.
A proposal should be able to explain what are you doing via the code. What is the logic behind it?
It is important for us to know so that we can analyze whether it could be a problem with other parts of the code.
Given the nature of discussion happening here, I'd like to provide some more context to my proposal above.
While the linked github issue has a lengthy discussion on the topic I'll do my best to provide a tl;dr even though I don't necessarily understand the underlying Java code.
The best summary I found actually comes from react-navigation docs where they recommend applying this exact fix the moment you install the library. Their reasoning is that
This change is required to avoid crashes related to View state being not persisted consistently across Activity restarts.
So instead of trying to fix the state consistency, the fix is to simply discard the state and basically restart the app. You can see that on the video in my proposal, there is a loading animation and splash screen every time you adjust the split, which is a terrible user experience.
Meanwhile, the fix proposed by @hiteshagja doesn't have that flaw. I have just given it a try and it works without the app restart.
So unless his fix has some downside, expensify should go with it. Even though it is kinda weird that @hiteshagja has submitted a PR without being hired for the job first.
I am in talks about this https://expensify.slack.com/archives/C01GTK53T8Q/p1639152620014500. Thanks for the insights guys.
So unless his fix has some downside, expensify should go with it. Even though it is kinda weird that @hiteshagja has submitted a PR without being hired for the job first.
Good point @dklymenk. According to our contribution guideline, a contributor is not allowed to submit the PR until his proposal is accepted. Could you please close that PR and wait for further instructions @hiteshagja ?
Closed PR. I will wait for your message @parasharrajat
No update on Slack. waiting for a conclusion there.
Thanks Everyone for waiting. Based on the Slack discussion, we would like to prevent the app from crashing but do not want to support Split mode for now.
So a proposal should do this:
- Prevent app from crashing.
- Block the app from going into split mode.
- A native alert should be shown to the user that split mode is not supported for this app.
Could you please share new proposal for the above requirements?
Hi, here is a proposal that covers the new requirements:
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index ed644b54e..d416c3cb2 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -22,6 +22,7 @@
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
+ android:resizeableActivity="false"
android:theme="@style/AppTheme">
<activity
Adding that line in the application section of AndroidManifest.xml makes the entire app non-resizable. It hides the split screen button from the application's context menu on the list of thumbnail images you get when you press the Overview button. It also produces the native alert if you manage to get around the missing button on the context menu as well as preventing the crash.
https://user-images.githubusercontent.com/64093836/146653110-035af500-946f-498e-b9ba-14745f4c9f83.mp4
@hiteshagja Awaiting your proposal...