catch and show threading exceptions
This commit is contained in:
parent
57093254a0
commit
404f9dc4cc
|
@ -64,7 +64,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:db51b86628'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:a1ecb048c0'
|
||||
implementation 'com.facebook.stetho:stetho:1.5.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'com.shawnlin:number-picker:2.4.6'
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.simplemobiletools.clock.helpers.STOPWATCH_RUNNING_NOTIF_ID
|
|||
import com.simplemobiletools.clock.helpers.Stopwatch
|
||||
import com.simplemobiletools.clock.helpers.Stopwatch.State
|
||||
import com.simplemobiletools.clock.helpers.Stopwatch.UpdateListener
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
@ -24,7 +25,6 @@ import org.greenrobot.eventbus.Subscribe
|
|||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
class StopwatchService : Service() {
|
||||
|
||||
private val bus = EventBus.getDefault()
|
||||
private lateinit var notificationManager: NotificationManager
|
||||
private lateinit var notificationBuilder: NotificationCompat.Builder
|
||||
|
@ -114,7 +114,11 @@ class StopwatchService : Service() {
|
|||
|
||||
fun startStopwatchService(context: Context) {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
ContextCompat.startForegroundService(context, Intent(context, StopwatchService::class.java))
|
||||
try {
|
||||
ContextCompat.startForegroundService(context, Intent(context, StopwatchService::class.java))
|
||||
} catch (e: Exception) {
|
||||
context.showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.simplemobiletools.clock.helpers.INVALID_TIMER_ID
|
|||
import com.simplemobiletools.clock.helpers.TIMER_RUNNING_NOTIF_ID
|
||||
import com.simplemobiletools.clock.models.TimerEvent
|
||||
import com.simplemobiletools.clock.models.TimerState
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
|
@ -55,7 +56,11 @@ class TimerService : Service() {
|
|||
}
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
|
||||
try {
|
||||
startForeground(TIMER_RUNNING_NOTIF_ID, notification(formattedDuration, contextText, firstTimer.id!!))
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stopService()
|
||||
|
@ -122,7 +127,11 @@ class TimerService : Service() {
|
|||
|
||||
fun startTimerService(context: Context) {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
|
||||
try {
|
||||
ContextCompat.startForegroundService(context, Intent(context, TimerService::class.java))
|
||||
} catch (e: Exception) {
|
||||
context.showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue