You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a OnePlus phone, when installing and launching the app for the first time, there is no problem opening the service. However, when the service is triggered to close, the app crashes
Restart the app and repeat the above steps to avoid crashing
//=================================================================//
Log:
Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{716554a u0 com.sunnygrand.sleepbutler/id.flutter.flutter_background_service.BackgroundService}
Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{716554a u0 com.sunnygrand.sleepbutler/id.flutter.flutter_background_service.BackgroundService}
at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2331)
at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2302)
at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2628)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:255)
at android.os.Looper.loop(Looper.java:364)
at android.app.ActivityThread.main(ActivityThread.java:8979)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1053)
Caused by android.app.StackTrace
Last startServiceCommon() call for this service was made here
Caused by android.app.StackTrace: Last startServiceCommon() call for this service was made here
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1992)
at android.app.ContextImpl.startForegroundService(ContextImpl.java:1936)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:840)
at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java)
at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:700)
at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.start(FlutterBackgroundServicePlugin.java:83)
at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.onMethodCall(FlutterBackgroundServicePlugin.java:135)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:319)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:255)
at android.os.Looper.loop(Looper.java:364)
at android.app.ActivityThread.main(ActivityThread.java:8979)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1053)
Using a OnePlus phone, when installing and launching the app for the first time, there is no problem opening the service. However, when the service is triggered to close, the app crashes
Restart the app and repeat the above steps to avoid crashing
//=================================================================//
Flutter:3.22.3
compileSdkVersion 34
Device:OnePlus Ace 2V
Android:14
//=================================================================//
Log:
Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{716554a u0 com.sunnygrand.sleepbutler/id.flutter.flutter_background_service.BackgroundService}
Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{716554a u0 com.sunnygrand.sleepbutler/id.flutter.flutter_background_service.BackgroundService}
at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2331)
at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2302)
at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2628)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:255)
at android.os.Looper.loop(Looper.java:364)
at android.app.ActivityThread.main(ActivityThread.java:8979)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1053)
Caused by android.app.StackTrace
Last startServiceCommon() call for this service was made here
Caused by android.app.StackTrace: Last startServiceCommon() call for this service was made here
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1992)
at android.app.ContextImpl.startForegroundService(ContextImpl.java:1936)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:840)
at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java)
at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:700)
at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.start(FlutterBackgroundServicePlugin.java:83)
at id.flutter.flutter_background_service.FlutterBackgroundServicePlugin.onMethodCall(FlutterBackgroundServicePlugin.java:135)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:319)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:255)
at android.os.Looper.loop(Looper.java:364)
at android.app.ActivityThread.main(ActivityThread.java:8979)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1053)
//=================================================================//
Code:
@pragma('vm:entry-point')
void onStart(ServiceInstance bgService) async {
Log.d('SleepTextRoute=> Service onStart set');
bgService.on(SleepTextRoute.ROUTE_STAOP).listen((event) async {
Log.d('SleepTextRoute=>Service STOP_BYHAND');
await bgService.stopSelf();
});
Log.d("SleepTextRoute=>Service finish set");
}
Future startService() async {
Log.d('SleepTextRoute=> begin set');
AndroidNotificationChannel channel = AndroidNotificationChannel(
'my_sleep_notification', // id
S.current.notice_sleep_service_title, // title
description: 'This channel is used for important notifications.', // description
importance: Importance.low, // importance must be at low or higher level
);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
if (Platform.isIOS) {
await flutterLocalNotificationsPlugin.initialize(
const InitializationSettings(
iOS: DarwinInitializationSettings(),
android: AndroidInitializationSettings(R.loginLogo),
),
);
}
await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation()?.createNotificationChannel(channel);
await _bgService.configure(
androidConfiguration: AndroidConfiguration(
onStart: onStart,
// auto start service
autoStart: true,
isForegroundMode: true,
notificationChannelId: 'my_sleep_notification',
initialNotificationTitle: S.current.notice_sleep_service_title,
initialNotificationContent: S.current.notice_sleep_service_tip,
foregroundServiceNotificationId: 888,
foregroundServiceTypes: [AndroidForegroundType.microphone]
),
iosConfiguration: IosConfiguration(
autoStart: true,
onForeground: onStart,
onBackground: onIosBackground,
),
);
Log.d('SleepTextRoute=> start set');
}
The text was updated successfully, but these errors were encountered: