Commit 184f554d authored by 周文华's avatar 周文华

【修复】同步修复部分可能的崩溃

parent 63404314
......@@ -447,10 +447,11 @@ object NotificationUtil {
val delay: Long =
AppPreferences.getInstance().getString("delay", "0").toLongOrNull() ?: 0L
handlerThread = HandlerThread("NotificationHandlerThread")
handlerThread!!.start()
handlerThread?.start()
handlerThread?.let {
if (it.isAlive && it.looper != null) handler = Handler(it.looper)
}
// 创建 Handler
handler = Handler(handlerThread!!.looper)
for (i in 1..num) {
val time = i * delay
handler?.postDelayed(Runnable {
......
......@@ -125,6 +125,7 @@ class StayJobService : JobService() {
private fun startForeground() {
val notification = createPermanentNotification(applicationContext)
runCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
NOTIFICATION_PERMANENT_ID,
......@@ -133,7 +134,7 @@ class StayJobService : JobService() {
)
} else {
startForeground(NOTIFICATION_PERMANENT_ID, notification)
}
} }
isRunning = true
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment