GrantHandler

constructor(grantManager: GrantManager, grant: GrantPermission, scope: CoroutineScope, savedStateDelegate: SavedStateDelegate = NoOpSavedStateDelegate(), eventListener: GrantEventListener? = null)

Parameters

grantManager

The underlying grant manager

grant

The specific grant this handler manages (AppGrant or RawPermission)

scope

CoroutineScope for launching grant requests.

**CRITICAL - Scope Requirements:**
- **MUST** use [viewModelScope] from a ViewModel
- Survives configuration changes (screen rotation)
- Automatically cancelled when ViewModel is cleared
- Prevents memory leaks

**DO NOT USE:**
- [GlobalScope]: Never cancelled, causes memory leaks
- [lifecycleScope]: Cancelled on config changes, breaks ongoing requests
- Custom scopes with short lifecycle
- Any scope that doesn't outlive the grant flow

**Example of CORRECT usage:**
```kotlin
class MyViewModel : ViewModel() {
    val handler = GrantHandler(..., scope = viewModelScope) // ✅ Correct
}
```

**Example of WRONG usage:**
```kotlin
class MyFragment : Fragment() {
    val handler = GrantHandler(..., scope = lifecycleScope) // ❌ Wrong!
    // This breaks on screen rotation!
}
```
savedStateDelegate

Optional delegate for saving/restoring state across process death. Use AndroidSavedStateDelegate on Android for automatic restoration. Defaults to NoOpSavedStateDelegate (no persistence).