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,6 +69,7 @@ object TiebaUtil {
fun startSign(context: Context) { fun startSign(context: Context) {
context.appPreferences.signDay = Calendar.getInstance()[Calendar.DAY_OF_MONTH] context.appPreferences.signDay = Calendar.getInstance()[Calendar.DAY_OF_MONTH]
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
context.startForegroundService( context.startForegroundService(
Intent() Intent()
.setClassName( .setClassName(
@ -78,6 +79,9 @@ object TiebaUtil {
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setAction(OKSignService.ACTION_START_SIGN) .setAction(OKSignService.ACTION_START_SIGN)
) )
} catch (e: IllegalStateException) {
e.printStackTrace()
}
} else { } else {
context.startService( context.startService(
Intent() Intent()