我的 mvvmcross android 表单应用程序中有工作服务,该应用程序正在检查来自服务器的数据,如果是新帖子,则创建新通知。检查新帖子的代码正在使用中,所以我必须初始化 mvvmcross IoC,但那时我遇到了错误。 [Service(Exported = true, Permission = "android.permission.BIND_JOB_SERVICE")] public class NotificationJobService : JobService { private static readonly string TAG = "ExampleJobService"; public override bool OnStartJob(JobParameters args) { Log.Info(TAG, "on start job: " + args.JobId); DoBackgroundWork(args); return true; } public override bool OnStopJob(JobParameters args) { return true; } private void DoBackgroundWork(JobParameters args) { new Thread(() => { var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext); setupSingleton.EnsureInitialized(); Mvx.IoCProvider.Resolve<INotificationService>().ShowNewPostNotification(new Newsfeed()); JobFinished(args, true); }).Start(); } } [Activity(Label = "SurrenderAt20", MainLauncher = true, Theme = "@style/MainTheme", NoHistory = false, ScreenOrientation = ScreenOrientation.Portrait)] public class MainActivity : MvxFormsAppCompatActivity<AndroidSetup, CoreApp, App> { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); StartJob(); } void StartJob() { Class javaClass = Class.FromType(typeof(NotificationJobService)); ComponentName componentName = new ComponentName(this, javaClass); JobInfo info = new JobInfo.Builder(123, componentName) .SetMinimumLatency(20000) .SetOverrideDeadline(25000) .SetPersisted(true) .Build(); }}
- 1 回答
- 0 关注
- 113 浏览
添加回答
举报
0/150
提交
取消
