diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt index bcf68e67ecbd..6a8132d32d5e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt @@ -15,6 +15,7 @@ import android.widget.TextView import androidx.annotation.ColorInt import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat +import androidx.fragment.app.FragmentActivity import androidx.recyclerview.widget.RecyclerView import com.google.android.material.color.MaterialColors import com.google.android.material.datepicker.CalendarConstraints @@ -59,6 +60,9 @@ class SettingsAdapter( val settings: Settings? get() = fragmentView.settings + val fragmentActivity: FragmentActivity + get() = fragmentView.fragmentActivity + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SettingViewHolder { val inflater = LayoutInflater.from(parent.context) return when (viewType) { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SwitchSettingViewHolder.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SwitchSettingViewHolder.kt index 48034dae41f6..ddcf1d39b5c2 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SwitchSettingViewHolder.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/viewholder/SwitchSettingViewHolder.kt @@ -61,8 +61,8 @@ class SwitchSettingViewHolder( if (setting.setting === BooleanSetting.MAIN_EMULATE_WII_SPEAK && isChecked) { if (!PermissionsHandler.hasRecordAudioPermission(itemView.context)) { - val settingsActivity = itemView.context as Activity - PermissionsHandler.requestRecordAudioPermission(settingsActivity) + val currentActivity = adapter.fragmentActivity as Activity + PermissionsHandler.requestRecordAudioPermission(currentActivity) } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ActivityTracker.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ActivityTracker.kt index c5bc6cac208b..b0f7429af331 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ActivityTracker.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ActivityTracker.kt @@ -10,13 +10,12 @@ class ActivityTracker : ActivityLifecycleCallbacks { var currentActivity : Activity? = null private set - override fun onActivityCreated(activity: Activity, bundle: Bundle?) { - currentActivity = activity - } + override fun onActivityCreated(activity: Activity, bundle: Bundle?) {} override fun onActivityStarted(activity: Activity) {} override fun onActivityResumed(activity: Activity) { + currentActivity = activity resumedActivities.add(activity) if (!backgroundExecutionAllowed && !resumedActivities.isEmpty()) { backgroundExecutionAllowed = true @@ -25,6 +24,9 @@ class ActivityTracker : ActivityLifecycleCallbacks { } override fun onActivityPaused(activity: Activity) { + if (currentActivity === activity) { + currentActivity = null + } resumedActivities.remove(activity) if (backgroundExecutionAllowed && resumedActivities.isEmpty()) { backgroundExecutionAllowed = false @@ -36,11 +38,7 @@ class ActivityTracker : ActivityLifecycleCallbacks { override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {} - override fun onActivityDestroyed(activity: Activity) { - if (currentActivity === activity) { - currentActivity = null - } - } + override fun onActivityDestroyed(activity: Activity) {} companion object { @JvmStatic