From d60099738d1097b02503af839975b171c2d83853 Mon Sep 17 00:00:00 2001 From: ARIYAMA Keiji Date: Wed, 15 Dec 2021 22:56:59 +0900 Subject: [PATCH] Fix the WorkManager scheduling issue. --- .../Covid19Radar.Android/MainActivity.cs | 3 +++ .../Covid19Radar.Android/MainApplication.cs | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Covid19Radar/Covid19Radar.Android/MainActivity.cs b/Covid19Radar/Covid19Radar.Android/MainActivity.cs index 79b768f99..0f0a80bf5 100644 --- a/Covid19Radar/Covid19Radar.Android/MainActivity.cs +++ b/Covid19Radar/Covid19Radar.Android/MainActivity.cs @@ -18,6 +18,7 @@ using Covid19Radar.Common; using Covid19Radar.Services.Logs; using Prism.Ioc; +using AndroidX.AppCompat.App; namespace Covid19Radar.Droid { @@ -83,6 +84,8 @@ protected override async void OnCreate(Bundle savedInstanceState) base.SetTheme(Resource.Style.MainTheme); base.OnCreate(savedInstanceState); + AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo; + Xamarin.Forms.Forms.SetFlags("RadioButton_Experimental"); Xamarin.Essentials.Platform.Init(this, savedInstanceState); Xamarin.Forms.Forms.Init(this, savedInstanceState); diff --git a/Covid19Radar/Covid19Radar.Android/MainApplication.cs b/Covid19Radar/Covid19Radar.Android/MainApplication.cs index bdfa266f0..51a34053d 100644 --- a/Covid19Radar/Covid19Radar.Android/MainApplication.cs +++ b/Covid19Radar/Covid19Radar.Android/MainApplication.cs @@ -15,7 +15,6 @@ using Chino; using Chino.Android.Google; using System.Collections.Generic; -using AndroidX.AppCompat.App; using Prism.Ioc; namespace Covid19Radar.Droid @@ -35,13 +34,18 @@ private readonly JobSetting _exposureDetectedV2JobSetting = new JobSetting(INITIAL_BACKOFF_MILLIS, Android.App.Job.BackoffPolicy.Linear, true); private readonly JobSetting _exposureNotDetectedJobSetting = null; - private Lazy _exposureNotificationApiService = new Lazy(() => ContainerLocator.Current.Resolve()); private Lazy _exposureDetectionService = new Lazy(() => ContainerLocator.Current.Resolve()); + private Lazy _exposureDetectionBackgroundService + = new Lazy(() => ContainerLocator.Current.Resolve()); + + private Lazy _loggerService + = new Lazy(() => ContainerLocator.Current.Resolve()); + public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer) { } @@ -62,8 +66,6 @@ public override void OnCreate() { base.OnCreate(); - AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo; - App.InitializeServiceLocator(RegisterPlatformTypes); AbsExposureNotificationClient.Handler = this; @@ -71,6 +73,15 @@ public override void OnCreate() { SetupENClient(exposureNotificationApiService.Client); } + + try + { + _exposureDetectionBackgroundService.Value.Schedule(); + } + catch (Exception exception) + { + _loggerService.Value.Exception("failed to Scheduling", exception); + } } private void SetupENClient(ExposureNotificationClient client)