protected override void OnCreate(Bundle bundle) { AndroidEnvironment.UnhandledExceptionRaiser += OnAndroidEnvironmentOnUnhandledExceptionRaiser; TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); Forms.Init(this, bundle); LoadApplication(new App(new AndroidInitializer())); CrossCurrentActivity.Current.Init(this, bundle); var builder = new AndroidBackgroundServiceHostBuilder(); builder .WithAndroidServiceName("YOUR_SERVICE_NAME") .WithNotification( $"{Application.PackageName}.YOUR_SERVICE_NAME", $"{Application.PackageName}.YOUR_SERVICE_NAME", NotificationImportance.Low, NotificationVisibility.Public, Resource.Drawable.ic_media_play_light, // replace with your own icon. This is mandatory, otherwise the notification is not displayed correctly "SERVICE NOTIFICATION TITLE", "SERVICE NOTIFICATION CONTENT") .WithAppContext(this) .WithIntentLaunchType <MainActivity>() .WithPeriodicBackgroundService(new AliveService(), TimeSpan.FromSeconds(5)) .WithBackgroundService(new AccelerometerListenerService()) .WithBackgroundService(DependencyService.Resolve <IGeolocationService>() as IService); NativeBackgroundServiceHost.Init(builder); }
// // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); LoadApplication(new App(new iOSInitializer())); var builder = new iOSBackgroundServiceHostBuilder() .WithPeriodicBackgroundService(new AliveService(), TimeSpan.FromSeconds(5)) .WithBackgroundService(new AccelerometerListenerService()) .WithBackgroundService(DependencyService.Resolve <IGeolocationService>() as IService); NativeBackgroundServiceHost.Init(builder); return(base.FinishedLaunching(app, options)); }
protected override void OnCreate(Bundle bundle) { AndroidEnvironment.UnhandledExceptionRaiser += OnAndroidEnvironmentOnUnhandledExceptionRaiser; TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App(new AndroidInitializer())); NativeBackgroundServiceHost.Init( "YOUR_SERVICE_NAME", $"{Application.PackageName}.YOUR_SERVICE_NAME", "Your display service name", Resource.Drawable.ic_media_play_light, // replace with your own icon. This is mandatory, otherwise the notification is not displayed correctly "SERVICE NOTIFICATION TITLE", "SERVICE NOTIFICATION CONTENT", () => new BackgroundServiceHost(list => { list.Add(new AliveService()); // Should inherit from IService or IPeriodicService list.Add(new AccelerometerListenerService()); }, TimeSpan.FromSeconds(5)), // For periodic services, you can set the interval between calls typeof(MainActivity)); }