android-background-location-geofencinglisted
Install: claude install-skill lenorebreakneck630/claude-zero-to-hero-android-KMP
# Android Background Location and Geofencing
## Core Principles
- Foreground location and background location are separate permission tiers — request them independently and in sequence.
- Continuous tracking requires a Foreground Service with `foregroundServiceType="location"`.
- Geofences are battery-efficient; prefer them over polling when the requirement is proximity-based.
- Battery accuracy must match the actual product need — do not default to `PRIORITY_HIGH_ACCURACY`.
- Location code in the data layer; permission state and UI decisions in the presentation layer.
---
## Permission Tiers
Android enforces a two-step permission model for background location:
1. `ACCESS_FINE_LOCATION` or `ACCESS_COARSE_LOCATION` — required first.
2. `ACCESS_BACKGROUND_LOCATION` — can only be requested *after* the foreground permission is granted.
Declare in `AndroidManifest.xml`:
```xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- Required for Android 14+ foreground location service -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
```
**Do not** request `ACCESS_BACKGROUND_LOCATION` in the same launcher call as the foreground permission. The system ignores or rejects bundled requests on Android 11+.
---
## Permission Flow in Compose
Model all states explici