Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
Fix the issue that background task doesn't work in Android.
Browse files Browse the repository at this point in the history
I have confirmed that the worker task works better if the constraint `RequiresDeviceIdle` is not set to true.
  • Loading branch information
keiji committed Feb 28, 2021
1 parent 047b12b commit 2a840de
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Covid19Radar/Covid19Radar.Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,17 @@ public class MainApplication : Application
public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
{
}

public override void OnCreate()
{
base.OnCreate();

Xamarin.ExposureNotifications.ExposureNotification.ConfigureBackgroundWorkRequest(TimeSpan.FromHours(6), b =>
b.SetConstraints(new AndroidX.Work.Constraints.Builder()
.SetRequiresBatteryNotLow(true)
.SetRequiredNetworkType(AndroidX.Work.NetworkType.Connected)
.Build())
);
}
}
}

0 comments on commit 2a840de

Please sign in to comment.