From 657c72480e820f100884e14e809aef40e0081827 Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Thu, 31 Oct 2019 00:46:35 +0100 Subject: [PATCH] Some vendors' battery optimizers killed the background service quite quickly when the app is in the background and *not* playing music. This had the effect of breaking all player actions within the app (queue listing, playback control, etc.). This "starts" PlayerService every time MainActivity is resumed, which is a noop if the service is still running, but allows retrieving app functionality otherwise. --- app/build.gradle.kts | 4 ++-- app/src/main/java/com/github/apognu/otter/Otter.kt | 2 +- .../java/com/github/apognu/otter/activities/MainActivity.kt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cd9eccb..881c351 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -90,8 +90,8 @@ dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.2") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.2") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2") implementation("androidx.appcompat:appcompat:1.1.0") implementation("androidx.core:core-ktx:1.2.0-beta01") diff --git a/app/src/main/java/com/github/apognu/otter/Otter.kt b/app/src/main/java/com/github/apognu/otter/Otter.kt index b0317d3..a117af0 100644 --- a/app/src/main/java/com/github/apognu/otter/Otter.kt +++ b/app/src/main/java/com/github/apognu/otter/Otter.kt @@ -17,7 +17,7 @@ class Otter : Application() { fun get(): Otter = instance } - var eventBus: BroadcastChannel = BroadcastChannel(10) + val eventBus: BroadcastChannel = BroadcastChannel(10) val commandBus: Channel = Channel(10) val requestBus: BroadcastChannel = BroadcastChannel(10) val progressBus: BroadcastChannel> = ConflatedBroadcastChannel() diff --git a/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt b/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt index f65d022..8642c55 100644 --- a/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt +++ b/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt @@ -59,8 +59,6 @@ class MainActivity : AppCompatActivity() { .replace(R.id.container, BrowseFragment()) .commit() - startService(Intent(this, PlayerService::class.java)) - watchEventBus() CommandBus.send(Command.RefreshService) @@ -69,6 +67,8 @@ class MainActivity : AppCompatActivity() { override fun onResume() { super.onResume() + startService(Intent(this, PlayerService::class.java)) + now_playing_toggle.setOnClickListener { CommandBus.send(Command.ToggleState) }