Skip to content
Snippets Groups Projects
Verified Commit 7211c75e authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Attempt at fixing more connection crashes

parent 3caa7f8e
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,6 @@ import android.content.ComponentName ...@@ -23,7 +23,6 @@ import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.ServiceConnection import android.content.ServiceConnection
import android.os.Build
import android.os.IBinder import android.os.IBinder
import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
...@@ -66,11 +65,18 @@ class BackendServiceConnection : ServiceConnection, DefaultLifecycleObserver { ...@@ -66,11 +65,18 @@ class BackendServiceConnection : ServiceConnection, DefaultLifecycleObserver {
} }
} }
fun start(intent: Intent = QuasselService.intent(context!!)) { fun start(intent: Intent? = null): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { try {
context?.startForegroundService(intent) context?.let {
} else { it.startService(
context?.startService(intent) intent
?: QuasselService.intent(it)
)
return true
}
return false
} catch (e: IllegalStateException) {
return false
} }
} }
...@@ -90,7 +96,9 @@ class BackendServiceConnection : ServiceConnection, DefaultLifecycleObserver { ...@@ -90,7 +96,9 @@ class BackendServiceConnection : ServiceConnection, DefaultLifecycleObserver {
} }
} }
override fun onCreate(owner: LifecycleOwner) = start() override fun onCreate(owner: LifecycleOwner) {
start()
}
override fun onStart(owner: LifecycleOwner) = bind() override fun onStart(owner: LifecycleOwner) = bind()
......
...@@ -26,6 +26,7 @@ import android.content.res.Configuration ...@@ -26,6 +26,7 @@ import android.content.res.Configuration
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.WindowManager import android.view.WindowManager
import android.widget.Toast
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import de.kuschku.libquassel.session.Backend import de.kuschku.libquassel.session.Backend
...@@ -151,7 +152,8 @@ abstract class ServiceBoundActivity : ...@@ -151,7 +152,8 @@ abstract class ServiceBoundActivity :
if (!reconnect || !accountIdValid) { if (!reconnect || !accountIdValid) {
onSelectAccount() onSelectAccount()
} else { } else {
connection.start() if (!connection.start())
Toast.makeText(this, "Could not create QuasselService", Toast.LENGTH_SHORT).show()
connection.bind() connection.bind()
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment