关闭应用程序或锁定屏幕时,Xamarin形式的光泽不会运行

问题描述

我正在尝试使用发亮的xamarin形式执行计划任务,但无法使其正常工作。我不确定自己在做什么错。当我在Visual Studio中运行该应用程序时,它似乎可以工作,但是当我拔下它时,打开该应用程序时,它只能运行一次。有什么建议吗?

MainApplication.cs

 [Application]
    class MainApplication : Application
    {
        public MainApplication(IntPtr handle,JniHandleOwnership ownerShip) : base(handle,ownerShip)
        {
        }
        public override void OnCreate()
        {
            base.OnCreate();
            Shiny.AndroidShinyHost.Init(this,new ShinyTest.Startup());
        }
    }

工作班

public class FirstJob : IJob
    {
        public FirstJob()
        {
        }

        public async Task<bool> Run(JobInfo jobInfo,CancellationToken cancelToken)
        {
            //things I want to do every job
            return true; // this is for iOS - try not to lie about this - return true when you actually do receive new data from the remote method
        }
    }

App.xaml.cs

public App()
        {
            InitializeComponent();

            MainPage = new MainPage();
        }

        protected override async void OnStart()
        {
            TimeSpan span = new TimeSpan(0,15,0);
            var job = new JobInfo(typeof(FirstJob),"FirstJob")
            {
                PeriodicTime = span,BatteryNotLow = false,DeviceCharging = false,requiredInternetAccess = InternetAccess.Any,Repeat = true //defaults to true,set to false to run once OR set it inside a job to cancel further execution
            };

            // lastly,schedule it to go - don't worry about scheduling something more than once,we just update if your job name matches an existing one
            await ShinyHost.Resolve<Shiny.Jobs.IJobManager>().Schedule(job);
        }

Startup.cs

public class Startup : ShinyStartup
    {
        public override void ConfigureServices(IServiceCollection services)
        {
            
        }
    }

MainActivity

[Activity(Label = "ShinyTest",Icon = "@mipmap/icon",Theme = "@style/MainTheme",MainLauncher = true,ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this,savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this,savedInstanceState);
            LoadApplication(new App());
        }
        public override void OnRequestPermissionsResult(int requestCode,string[] permissions,[GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode,permissions,grantResults);
            Shiny.AndroidShinyHost.OnRequestPermissionsResult(requestCode,grantResults);

            base.OnRequestPermissionsResult(requestCode,grantResults);
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)