Skip to content

Conversation

@Inuth0603
Copy link
Contributor

@Inuth0603 Inuth0603 commented Jan 3, 2026

Fixes #6599

Changes

  • Added permission state tracking in onPause and onResume within ExploreMapFragment.kt.
  • Map now refreshes only when permission state changes from denied to granted, preventing redundant refreshes on every resume.
  • This ensures the map data refreshes immediately when users grant location permission via system settings, without causing unnecessary API calls during normal app usage.

Testing

  • ✅ Verified on device: Map correctly centers on user location after returning from Settings with newly granted permissions.
  • ✅ Verified: Map does not refresh unnecessarily when backgrounding/foregrounding the app with permissions already granted.
  • ✅ Verified: No duplicate API calls during normal fragment lifecycle events.

Technical Approach

The fix tracks permission state across the pause/resume lifecycle using a boolean flag (hadLocationPermissionOnPause). This prevents the common issue where checking permissions in onResume() triggers refreshes on every app resume, not just when permissions actually change.

@rohit9625
Copy link
Collaborator

Hi, @Inuth0603
I think you should ask to get assigned to the issue first before opening a PR.

@Inuth0603
Copy link
Contributor Author

Hi, @Inuth0603 I think you should ask to get assigned to the issue first before opening a PR.

Hi @rohit9625, apologies for skipping that step! I have just commented on the issue requesting assignment. Thanks for guiding me.

@rohit9625
Copy link
Collaborator

No problem :)

- Added hadLocationPermissionOnPause field to track permission state
- Only refresh map when permission changes from denied to granted
- Prevents unnecessary refreshes during normal app lifecycle events
@RitikaPahwa4444
Copy link
Collaborator

On a fresh install, as soon as I open the Explore map, I get the permissions dialog. I choose allow this time. However, it doesn't take me to my current location.

- Added isWaitingForFirstLocation flag to track when waiting for first GPS fix
- Updated handleLocationUpdate to center map when first location arrives
- Modified locationPermissionGranted to wait for location instead of calling onMapReady immediately
- Fixes issue where map doesn't center on first-time permission grant
@Inuth0603
Copy link
Contributor Author

On a fresh install, as soon as I open the Explore map, I get the permissions dialog. I choose allow this time. However, it doesn't take me to my current location.

@RitikaPahwa4444 Thanks for catching that! I've pushed a fix for the first-time permission grant issue.

The problem was: When users grant permission for the first time via the in-app dialog, getLastLocation() returns null because no location has been cached yet. The code was requesting location updates but calling onMapReady() immediately without waiting for the first location to arrive.

The fix:

  • Added a flag isWaitingForFirstLocation to track when we're waiting for the first GPS fix
  • Modified locationPermissionGranted() to NOT call onMapReady() if location is null - instead it shows a progress indicator and waits
  • Updated handleLocationUpdate() to detect when the first location arrives and center the map at that point

This should now work for both scenarios:
✅ First-time permission grant (in-app dialog) - waits for GPS and centers map
✅ Returning from Settings after granting permission - auto-centers map

Could you test again when you get a chance? You can test by:

  1. Uninstalling and reinstalling the app (fresh install)
  2. Opening Explore map and granting permission via the in-app dialog
  3. Checking if it centers on your location

Thanks for the thorough testing! 🙏

@github-actions
Copy link

✅ Generated APK variants!

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.

[Bug]: explore map do not refresh automatically after enabling location services .

3 participants