From 8a2f0aca83a927f28fa8cb96dbb8758ff6931365 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Thu, 12 May 2022 01:10:22 +0800 Subject: [PATCH] Changed FunctionFactory.kt --- .../notify/utils/factory/FunctionFactory.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt b/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt index 0ebef5f..e75fdec 100644 --- a/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt +++ b/app/src/main/java/com/fankes/coloros/notify/utils/factory/FunctionFactory.kt @@ -370,15 +370,11 @@ fun toast(msg: String) = Toast.makeText(appContext, msg, Toast.LENGTH_SHORT).sho * * [T] 为指定的 [Activity] */ -inline fun Context.navigate() = runInSafe { startActivity(Intent(this, T::class.java)) } - -/** - * 跳转到指定页面 - * - * [T] 为指定的 [Activity] - */ -inline fun Service.navigate() = - runInSafe { startActivity(Intent(this, T::class.java).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK }) } +inline fun Context.navigate() = runInSafe { + startActivity(Intent(if (this is Service) applicationContext else this, T::class.java).apply { + if (this@navigate !is Activity) flags = Intent.FLAG_ACTIVITY_NEW_TASK + }) +} /** * 弹出 [Snackbar]