huzit
___을 입력해주세요
huzit
전체 방문자
  • 분류 전체보기 (137)
    • 안드로이드(Compose) (10)
      • UI (4)
      • 개념 (6)
    • 안드로이드 (50)
      • 기본개념 (6)
      • 응용 (4)
      • Debug (18)
      • Binding (3)
      • RecyclerView (5)
      • Firebase (6)
      • Retrofit (1)
      • Activity & Fragment (4)
    • 코틀린 (22)
    • 코딩테스트 (38)
      • 백준 (10)
      • 프로그래머스 (28)
    • 일상 (6)
    • CS 지식 (4)
    • 라즈베리파이 (7)

블로그 메뉴

  • 홈
  • 태그
  • 글쓰기
  • 관리

공지사항

인기 글

태그

  • FCM
  • 라즈베리 파이
  • 코틀린
  • Kotlin
  • 프로그래머스
  • recyclerView ClickEvent
  • 공돌이파파
  • Retrofit
  • 공돌카돈
  • Java
  • gts4mini
  • Android
  • jetpack
  • docker
  • firebase
  • RecyclerView
  • IFTTT
  • Debug
  • compose
  • 브레빌 밤비노 플러스

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
huzit

___을 입력해주세요

RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{dcc7ca6 u0 com.***.***/.ble.BleService}
안드로이드/Debug

RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{dcc7ca6 u0 com.***.***/.ble.BleService}

2023. 4. 13. 10:36
728x90

원인

서비스에서 startForeground 호출 시점이 꼬이면 발생하는 예외

초가 5개!!!!!


해결

onStartCommand() 에서 호출하던 startFroeground를 onCreate() 로 변경

private fun createNotificationChannel() {
		...
        startForeground(NOTIFICATION_ID, notification)
    }

    broadcastUpdate(BleObject.START_FOREGROUND_SERVICE, "startForegroundService")
}
override fun onCreate() {
    super.onCreate()
    createNotificationChannel()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    super.onStartCommand(intent, flags, startId)
    when (intent?.action) {
        BleObject.START_FOREGROUND_SERVICE -> {
            //createNotificationChannel() 여기에서 onCreate() 로 변경
            bleRepository.initBeaconManager(this)
            bleRepository.initBeaconListener(this)
            bleRepository.startBeaconScan()
        }
        BleObject.STOP_FOREGROUND_SERVICE -> {
            bleRepository.stopBeaconScan()
            stopForegroundService()
        }
        BleObject.READ_SENSOR -> {
            getSensorDataRoutin()
        }
    }
    // 작업 수행 코드
    return START_REDELIVER_INTENT
}

참고

https://stackoverflow.com/questions/44425584/context-startforegroundservice-did-not-then-call-service-startforeground

 

Android 8.0 동작 변경 사항  |  Android 개발자  |  Android Developers

System and API behavior changes that can affect apps running on Android 8.0.

developer.android.com

728x90
저작자표시 (새창열림)

'안드로이드 > Debug' 카테고리의 다른 글

Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.10 (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)  (0) 2023.05.25
java.lang.NullPointerException: null cannot be cast to non-null type androidx.navigation.fragment.NavHostFragment  (0) 2023.04.18
--- Failed to create image decoder with message 'unimplemented'  (0) 2023.04.10
Caused by: java.lang.IllegalArgumentException: Char / is not a decimal digit  (0) 2023.04.10
SDK location not found  (0) 2023.03.13
    '안드로이드/Debug' 카테고리의 다른 글
    • Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.10 (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)
    • java.lang.NullPointerException: null cannot be cast to non-null type androidx.navigation.fragment.NavHostFragment
    • --- Failed to create image decoder with message 'unimplemented'
    • Caused by: java.lang.IllegalArgumentException: Char / is not a decimal digit
    huzit
    huzit
    simple is best

    티스토리툴바