在startForegroundService时RemoteServiceException$ForegroundServiceDidNotStartInTimeException

日志

Explain: FATAL EXCEPTION: main
Process: org.primftpd, PID: 18395
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{50d0a06 u0 org.primftpd/.services.SshServerService c:org.primftpd}
at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2391)
at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2359) with tag AndroidRuntime

原因

代码当中没有(在几秒钟内)立即调用startForeground,而是做了其他事情再来调用,运行时可能会超时

解决

把类似于

 				// make service high priority
 				Notification notification = ServicesStartStopUtil.updateNonActivityUI(
 						service,
 						true,
 						service.prefsBean,
 						service.keyFingerprintProvider,
 						service.quickShareBean,
 						service.chosenIp);
 				service.startForeground(NotificationUtil.NOTIFICATION_ID, notification);
 			}

放前面即可

posted @ 2026-04-01 23:24  气温骤降  阅读(0)  评论(0)    收藏  举报