示例#1
0
        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);
        }
 /// <summary>
 /// Initialize the service host. Must be called after <see cref="FormsAppCompatActivity.LoadApplication"/>
 /// </summary>
 public static void Init(AndroidBackgroundServiceHostBuilder builder)
 {
     _builder = builder;
 }