onStart function
void
onStart(
- ServiceInstance serviceInstance
Implementation
@pragma('vm:entry-point')
void onStart(ServiceInstance serviceInstance) async {
// Removed DartPluginRegistrant.ensureInitialized();
if (serviceInstance is AndroidServiceInstance) {
serviceInstance.on('setAsForeground').listen((event) {
serviceInstance.setAsForegroundService();
});
serviceInstance.on('setAsBackground').listen((event) {
serviceInstance.setAsBackgroundService();
});
serviceInstance.on('stopService').listen((event) {
serviceInstance.stopSelf();
});
serviceInstance.setForegroundNotificationInfo(
title: "Background Service",
content: "Park Space background service.",
);
Timer.periodic(const Duration(seconds: 10), (timer) async {
if (await serviceInstance.isForegroundService()) {
String? currentUsername = await MessageService().getUsername();
debugPrint("currentUsername==============>$currentUsername");
if (currentUsername != null && currentUsername.isNotEmpty) {
print("object ========>");
await MessageService().checkForMessages(currentUsername);
} else {
debugPrint("Current username is null or empty.");
}
}
});
}
}