diff --git a/ui/src/main/java/com/wireguard/android/QuickTileService.kt b/ui/src/main/java/com/wireguard/android/QuickTileService.kt index f74c8bdf4..075fcda82 100644 --- a/ui/src/main/java/com/wireguard/android/QuickTileService.kt +++ b/ui/src/main/java/com/wireguard/android/QuickTileService.kt @@ -54,12 +54,7 @@ class QuickTileService : TileService() { null -> { val intent = Intent(this, MainActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { - startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)) - } else { - @Suppress("DEPRECATION") - startActivityAndCollapse(intent) - } + startActivityCompat(intent) } else -> { unlockAndRun { @@ -70,7 +65,7 @@ class QuickTileService : TileService() { } catch (_: Throwable) { val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java) toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - startActivity(toggleIntent) + startActivityCompat(toggleIntent) } } } @@ -78,6 +73,15 @@ class QuickTileService : TileService() { } } + private fun startActivityCompat(intent: Intent) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)) + } else { + @Suppress("DEPRECATION", "StartActivityAndCollapseDeprecated") + startActivityAndCollapse(intent) + } + } + override fun onCreate() { isAdded = true if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {