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