Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{f294fe6 u0 file_path}
at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2272)
at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2243)
at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2522)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:223)
at android.os.Looper.loop(Looper.java:324)
at android.app.ActivityThread.main(ActivityThread.java:8634)
at java.lang.reflect.Method.invoke(Method.java)
应用程序目标 sdk 更新到 33 后,少数用户遇到此崩溃
所有适用于 android 13,并且大多数发生在应用程序处于后台时,而不是特定于设备
在
startForeground(id, notification)
获得
intent
后不久我就有了
onStartCommand
当您调用 starforgroundservice(intent) 然后在 oncreate 上调用 startforground(int,notification) 时会发生这种情况,当该操作需要更多时间来执行时,它会抛出此异常,或者您立即启动和停止服务,,,,
尝试调用startforground oncreate,因为你只有5秒的时间来调用它,否则系统将停止服务并且不会立即启动和停止服务
希望这对您有帮助