Repository: skyline-emu/skyline
File: app/src/main/java/emu/skyline/EmulationActivity.kt (Kotlin)

Code before:
    override fun onStart() {
        super.onStart()

        onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
            override fun handleOnBackPressed() {
                returnFromEmulation()
            }
        })
    }

    override fun onResume() {
        super.onResume()

        changeAudioStatus(true)

        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
            @Suppress("DEPRECATION")
            window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_FULLSCREEN)
        }
    }

    /**
     * Stop the currently executing ROM and replace it with the one specified in the new intent
     */
    override fun onNewIntent(intent : Intent?) {
        super.onNewIntent(intent!!)
        if (getIntent().data != intent.data) {
            setIntent(intent)
            executeApplication(intent)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        shouldFinish = false

        // Stop forcing 60Hz on exit to allow the skyline UI to run at high refresh rates
        getSystemService<DisplayManager>()?.unregisterDisplayListener(this)
        force60HzRefreshRate(false)
        if (emulationSettings.forceMaxGpuClocks)
            GpuDriverHelper.forceMaxGpuClocks(false)

        stopEmulation(false)
        vibrators.forEach { (_, vibrator) -> vibrator.cancel() }
        vibrators.clear()
    }

Review comment (suggestion):
```suggestion
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S)
            enterPictureInPictureMode(PictureInPictureParams.Builder().build())
```

Code after:
            hapticFeedback = appSettings.onScreenControl && appSettings.onScreenControlFeedback
            recenterSticks = appSettings.onScreenControlRecenterSticks
        }

        binding.onScreenControllerToggle.apply {
            isGone = binding.onScreenControllerView.isGone
            setOnClickListener { binding.onScreenControllerView.isInvisible = !binding.onScreenControllerView.isInvisible }
        }

        binding.onScreenPauseToggle.apply {
            isGone = binding.onScreenControllerView.isGone
            setOnClickListener {
                if (isEmulatorPaused) {
                    resumeEmulator()
                    binding.onScreenPauseToggle.setImageResource(R.drawable.ic_pause)
                } else {
                    pauseEmulator()
                    binding.onScreenPauseToggle.setImageResource(R.drawable.ic_play)
                }
            }
        }

        executeApplication(intent!!)
    }

    @SuppressWarnings("WeakerAccess")
    fun pauseEmulator() {
        if (isEmulatorPaused) return
        setSurface(null)
        changeAudioStatus(false)
        isEmulatorPaused = true
    }

    @SuppressWarnings("WeakerAccess")
    fun resumeEmulator() {
        if (!isEmulatorPaused) return
        gameSurface?.let { setSurface(it) }
        if (!emulationSettings.isAudioOutputDisabled)
            changeAudioStatus(true)
        isEmulatorPaused = false
    }

    override fun onPause() {
        super.onPause()

        if (emulationSettings.forceMaxGpuClocks)
            GpuDriverHelper.forceMaxGpuClocks(false)

        pauseEmulator()
    }