fix: remove location manager and update listener on pause #6483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description (required)
Fixes #6480
What changes did you make and why?
When we navigate to Explore -> Map, it registers
LocationManagerandLocationUpdateListener, which keep track of location changes and callhandleLocationUpdate, which further callsisNetworkConnectionEstablished, which is a method overridden byExploreMapFragment, and it is supposed to access the context using therequireActivitymethod.However, when we navigate away from the
ExploreMapFragment, it becomes detached from itsActivity. Despite this, theLocationManagercontinues to hold a reference to the fragment since it implementsLocationUpdateListener. As a result, when the app is relaunched and opens the Contributions screen, background location updates still try to access the detached fragment’s context, causing an IllegalStateException.To fix this, I now unregister the
LocationUpdateListenerandLocationManagerinonPause(). This ensures location updates stop when the fragment is no longer visible (such as when navigating back), preventing memory leaks and invalid context access.Tests performed (required)
Tested prodDebug on Pixel 9 Emulator with API level 35.
Screenshots (for UI changes only)
Screen_recording_20251011_191638.webm