Невозможно остановить службу с IndexOutOfBoundsException - PullRequest
0 голосов
/ 17 января 2020

мое приложение показывает интересные сбои. Я добавляю 4 наиболее распространенных логов cra sh, но не могу их объяснить. Кто-нибудь сталкивался с подобной проблемой? ps Я не использую ArrayList в моем коде.

Fatal Exception: java.lang.RuntimeException: Unable to stop service workers.BackgroundPlayer@c853ae2: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

Caused by java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
   at java.util.ArrayList.remove(ArrayList.java:477)
   at androidx.lifecycle.LifecycleRegistry.popParentState(LifecycleRegistry.java:202)
   at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:317)
   at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:334)
   at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
   at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
   at androidx.lifecycle.ServiceLifecycleDispatcher$DispatchRunnable.run(ServiceLifecycleDispatcher.java:105)
   at androidx.lifecycle.ServiceLifecycleDispatcher.postDispatchRunnable(ServiceLifecycleDispatcher.java:45)
   at androidx.lifecycle.ServiceLifecycleDispatcher.onServicePreSuperOnDestroy(ServiceLifecycleDispatcher.java:81)
   at androidx.lifecycle.LifecycleService.onDestroy(LifecycleService.java:70)
   at workers.BackgroundPlayer.onDestroy(streamPlayer.kt:385)

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1
   at java.util.ArrayList.remove(ArrayList.java:486)
   at androidx.lifecycle.LifecycleRegistry.popParentState(LifecycleRegistry.java:202)
   at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:301)
   at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
   at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
   at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
   at androidx.lifecycle.ServiceLifecycleDispatcher$DispatchRunnable.run(ServiceLifecycleDispatcher.java:105)
   at android.os.Handler.handleCallback(Handler.java:761)
   at android.os.Handler.dispatchMessage(Handler.java:98)
   at android.os.Looper.loop(Looper.java:156)
   at android.app.ActivityThread.main(ActivityThread.java:6523)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1
   at java.util.ArrayList.add(ArrayList.java:468)
   at androidx.lifecycle.LifecycleRegistry.pushParentState(LifecycleRegistry.java:206)
   at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:299)
   at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:339)
   at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
   at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:131)
   at androidx.lifecycle.ServiceLifecycleDispatcher$DispatchRunnable.run(ServiceLifecycleDispatcher.java:105)

Класс обслуживания:

class BackgroundPlayer : LifecycleService() {

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    super.onStartCommand(intent, flags, startId)

    return START_NOT_STICKY
}

// Start service player

fun start() {
    Thread {
        run {
            settingsLastPlayed(station)

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) startForegroundService(Intent(this, BackgroundPlayer::class.java).apply { putExtra(station) })
            else                                                startService(Intent(this, BackgroundPlayer::class.java)          .apply { putExtra(station) })
        }
    }.start()
}

override fun onDestroy() {
    releasePlayer()
    cancelRecording()

    super.onDestroy()
}

private fun releasePlayer() {
    mediaSession             ?.release()
    mediaSessionConnector    ?.setPlayer(null)
    playerNotificationManager?.setPlayer(null)
    exoPlayer                ?.release()
}

}

...