如何解决关闭应用程序或锁定屏幕时,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 举报,一经查实,本站将立刻删除。