Avoid context leak lint warning

This commit is contained in:
Naveen 2022-12-16 05:29:08 +05:30
parent 3304051720
commit 105d127a0b
2 changed files with 4 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package com.simplemobiletools.musicplayer.helpers
import android.annotation.TargetApi
import android.app.Application
import android.content.Context
import android.media.AudioAttributes
import android.media.AudioFocusRequest
@ -8,12 +9,12 @@ import android.media.AudioManager
import android.os.Build
@TargetApi(Build.VERSION_CODES.O)
class OreoAudioFocusHandler constructor(val context: Context) {
class OreoAudioFocusHandler constructor(val app: Application) {
private var audioFocusRequest: AudioFocusRequest? = null
private var audioManager: AudioManager? = null
init {
audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager = app.getSystemService(Context.AUDIO_SERVICE) as AudioManager
}
fun abandonAudioFocus() {

View file

@ -120,7 +120,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
mAudioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
if (isOreoPlus()) {
mOreoFocusHandler = OreoAudioFocusHandler(applicationContext)
mOreoFocusHandler = OreoAudioFocusHandler(application)
}
if (!isQPlus() && !hasPermission(getPermissionToRequest())) {