-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(upload): Prevent UploadProgressActivity restart and fix presenter initialization crash #6568
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
base: main
Are you sure you want to change the base?
fix(upload): Prevent UploadProgressActivity restart and fix presenter initialization crash #6568
Conversation
…PendingUploadsFragment
…restart on resize
|
@Kota-Jagadeesh thanks for the PR. Would you mind elaborating how this approach is different from the PR you closed (#6532) and why you suggest it over the one we discussed before? |
Thanks for following up on PR #6532.
That previous PR was a architecturall improovment to the Here is the elaboraton on why the current PR is different and why I suggest it over the one we previously discused: The Core Problem and the Two ApproachesThe crash,
2. Why i feel the current Approach is BetterEliminates the Root Cause (Manifest Change)The crash happens becuz the
Maintains Best Practice (Fragment Code)The previous approach in PR #6532 focused on making the Activity's fragment lookup safe, but it left the fragment internal
In a shorrt summary summary, the previous PR was a workaround for the symptom by making the fragment lookups safe. Thiss current PR is a proper fix (IMO) that addresses the root cause (Activity restart in the Manifest) and adds the robust defensive programmingg in the fragment. This ensures stability, better good performance (no full Activity restart), and adherence to the Dagger/MVP contract by keeping the presenteer non-nullable. Thanks : ) |
As per my understanding, we did figure out and address the root cause. Could you please elaborate what was missing there?
It wasn't a timing error as it was always reproducible, even after waiting for a long time. I would suggest reading https://developer.android.com/guide/topics/resources/runtime-changes for understanding configuration changes in depth, otherwise it's a rabbit hole. |
|
thank you for the detailed feedback and for the resource link - I definitely agree that understanding configuration chnages in depth is key to avoiding rabbit holes! I need to apologize for my previous phrasing "i understood i didnt phrase it properly" ; you are entirely correct. Calling it a "timing error" was misleeding. It should better be described as a Deterministic Lifecycle Ordering Issue that leads to this crash when an external call (from the Activity's menu handler) interrupts the fragments dependency re-injection sequence. Since the Activity always restarts, the crash is always reproducible. Here is the breakdown of what PR #6532 fixed versus what was still missing to fix the 1. Two "Root Causes" to AddressThe crash has two distinct dependency issues, and PR #6532 only fixed one:
What was missing was addressing the Activity restart itself (the true root cause of the lifecycle problem) and adding a safety check inside the Fragment for the Dagger contract. 2. Why the Current PR is the Complete FixThe current PR is superior because it applies the proper dual fix: A. Eliminating the Activity Restart (Manifest Fix)
B. Defending the Dagger Contract (Fragment Fix)
In short, PR #6532 made the Activity's menu code robust against null fragments, but it didn't solve the Fragment's presenter initialization crash. The current PR solves the latter by stopping the Activity restart and adding the necessary Dagger safety check. This gives us maximum stability and prevents the consistently reproducible crash. |
It is supposed to get recreated and there's nothing to fix.
Did those logs not prove otherwise? Could you please share some data points, steps to reproduce or links to issue trackers or stack overflow that suggest this is a known issue? I would again suggest reading the official docs and coming up with the cons of the approach you followed in this PR; there are always some tradeoffs in software engineering. Do share what we're gaining and at what cost. Thanks! :) |
|
@RitikaPahwa4444 Thank you for the detailed feedback on the above commentt. This is a very important point about the architecture, and I thank you guiding me to the official documentation. I believe the confusion over the "root cause" stems from needing to solve two different problems: 1. Why the Crash is a "Fixable Timing Issue"You are absolutely correct that the Activity is supposed to get recreated on configuration changes by default. However, this "recreation" (destroy --> create) is precisely what causes the crash.
By using the 2. What We Gain
In short, we are gaining stability and UX at the cost of giving up automatic resource reloading, which is the necessary and known tradeoff when using g please correct me if i am wrong, Thank you!! |
|
✅ Generated APK variants! |
This isn't happening as it's not a timing problem, it also occurs long after the configuration change. Could you share the specific data points behind this? You’ve raised it a few times, and I want to align on facts rather than assumptions.
There are caveats - we can't always prevent it on newer devices. Kindly read the documentation for more details.
Let's keep the fix limited to the scope of the issue instead of fixing any "potential" issues we haven't been able to reproduce so far. Also, I'm still confused why the other PR had been termed as a "workaround" while this one itself has caveats as we're just trying to stop activity recreation, which isn't ideal. Could you please share what kind of configuration changes, apart from screen rotation, have you tested for while working on this PR? This change is expected to impact all of them, unlike the previous PR. Also, this question from my previous comment is still unresolved:
|
Description (required)
Fixes #6433
Whatt changes did you make and why?
This PR fixes a critical crash in the upload progress screen that occurs when the device is rotated or resized while uploads are pending, and the user quickly interacts with the "Pause" or "Cancel" menu item.
The fix addresses both the root cause (Activity restart) and the specific crash location (Uninitialized Presenter):
1. Prevent Activity Restart (
AndroidManifest.xml)The
UploadProgressActivitywas restarting during configuration changes (like rotation or split-screen resize). This restart cycle caused the app to call fragment methods before Dagger could re-inject the dependencies.smallestScreenSizeandscreenLayoutto theandroid:configChangesattribute forUploadProgressActivity. This prevents the activity from being destroyed on resize events, thereby preserving the fragment's state and preventing the presenter from becoming uninitialized.2. Defensive Presenter Access (
PendingUploadsFragment.kt)Even with the Manifest change, fast user interaction or edge cases in the activity lifecycle could still lead to a crash.
if (::pendingUploadsPresenter.isInitialized)torestartUploads(),pauseUploads(), anddeleteUploads(). This ensures that the presenter is ready before any businesss logic methods are called, robustly preventing thekotlin.UninitializedPropertyAccessExceptioncrash which was used to ocurr.Tests performed (required)
Tested
ProdDebugonRedmi note 13 pro 5gwith API level35.