Skip to content

Conversation

@rohit9625
Copy link
Collaborator

Description (required)

Fixes #6480

What changes did you make and why?

When we navigate to Explore -> Map, it registers LocationManager and LocationUpdateListener, which keep track of location changes and call handleLocationUpdate, which further calls isNetworkConnectionEstablished, which is a method overridden by ExploreMapFragment, and it is supposed to access the context using the requireActivity method.

However, when we navigate away from the ExploreMapFragment, it becomes detached from its Activity. Despite this, the LocationManager continues to hold a reference to the fragment since it implements LocationUpdateListener. 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 LocationUpdateListener and LocationManager in onPause(). This ensures location updates stop when the fragment is no longer visible (such as when navigating back), preventing memory leaks and invalid context access.

Note: It also fixes a memory leak caused by ExploreMapFragment.

Tests performed (required)

Tested prodDebug on Pixel 9 Emulator with API level 35.

Screenshots (for UI changes only)

Screen_recording_20251011_191638.webm

@rohit9625
Copy link
Collaborator Author

Hi @nicolas-raoul, I've fixed this issue and tested it on my devices as well. Please test this branch on your end, as you also were able to reproduce this issue.

@github-actions
Copy link

✅ Generated APK variants!

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That fixes the issue, thanks!

@nicolas-raoul nicolas-raoul merged commit 14d6c80 into commons-app:main Oct 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reproducible crash when opening Explore>Map then exiting+opening app

2 participants