fix: 前台服务被限制启动导致闪退

This commit is contained in:
HuanCheng65 2022-06-16 12:35:54 +08:00
parent 366810b78c
commit e79ead4594
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
1 changed files with 13 additions and 9 deletions

View File

@ -69,15 +69,19 @@ object TiebaUtil {
fun startSign(context: Context) {
context.appPreferences.signDay = Calendar.getInstance()[Calendar.DAY_OF_MONTH]
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(
Intent()
.setClassName(
context.packageName,
"${context.packageName}.services.OKSignService"
)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setAction(OKSignService.ACTION_START_SIGN)
)
try {
context.startForegroundService(
Intent()
.setClassName(
context.packageName,
"${context.packageName}.services.OKSignService"
)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setAction(OKSignService.ACTION_START_SIGN)
)
} catch (e: IllegalStateException) {
e.printStackTrace()
}
} else {
context.startService(
Intent()