mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
make sure we launch startForeground from the main thread
This commit is contained in:
@ -5,7 +5,9 @@ import android.app.NotificationManager
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.simplemobiletools.clock.R
|
||||
@ -110,7 +112,9 @@ class StopwatchService : Service() {
|
||||
}
|
||||
|
||||
fun startStopwatchService(context: Context) {
|
||||
ContextCompat.startForegroundService(context, Intent(context, StopwatchService::class.java))
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
ContextCompat.startForegroundService(context, Intent(context, StopwatchService::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
object StopwatchStopService
|
||||
|
@ -6,7 +6,9 @@ import android.app.NotificationManager
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.simplemobiletools.clock.R
|
||||
@ -50,7 +52,10 @@ class TimerService : Service() {
|
||||
firstTimer.label.isNotEmpty() -> getString(R.string.timer_single_notification_label_msg, firstTimer.label)
|
||||
else -> resources.getQuantityString(R.plurals.timer_notification_msg, runningTimers.size, runningTimers.size)
|
||||
}
|
||||
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
|
||||
}
|
||||
} else {
|
||||
stopService()
|
||||
}
|
||||
@ -109,7 +114,9 @@ class TimerService : Service() {
|
||||
}
|
||||
|
||||
fun startTimerService(context: Context) {
|
||||
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
object TimerStopService
|
||||
|
Reference in New Issue
Block a user