Skip to content

Commit

Permalink
Merge pull request #66 from KoalaSat/recover-background-service
Browse files Browse the repository at this point in the history
Recover background service
  • Loading branch information
KoalaSat authored Dec 20, 2024
2 parents b4850d9 + a31d980 commit 35ca19c
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,7 @@ class NotificationsService : Service() {
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d("Pokey", "Starting foreground service...")
startForeground(1, createNotification())
keepAlive()

startSubscription()

val connectivityManager =
(getSystemService(ConnectivityManager::class.java) as ConnectivityManager)
connectivityManager.registerDefaultNetworkCallback(networkCallback)
startService()

return START_STICKY
}
Expand All @@ -213,6 +205,23 @@ class NotificationsService : Service() {
super.onDestroy()
}

private fun startService() {
try {
Log.d("Pokey", "Starting foreground service...")
startForeground(1, createNotification())
keepAlive()

startSubscription()

val connectivityManager =
(getSystemService(ConnectivityManager::class.java) as ConnectivityManager)
connectivityManager.registerDefaultNetworkCallback(networkCallback)
} catch (e: Exception) {
Log.e("NotificationsService", "Error in service", e)
startService()
}
}

private fun startSubscription() {
if (!Client.isSubscribed(clientNotificationListener)) Client.subscribe(clientNotificationListener)

Expand Down

0 comments on commit 35ca19c

Please sign in to comment.