为了账号安全,请及时绑定邮箱和手机立即绑定

如何在应用程序关闭时在android作业服务中初始化mvvmcross表单IoC以使用注册服务?

如何在应用程序关闭时在android作业服务中初始化mvvmcross表单IoC以使用注册服务?

C#
叮当猫咪 2022-07-23 18:02:36
我的 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 回答

?
呼如林

TA贡献1798条经验 获得超3个赞

问题最初在评论中回答并作为答案发布,希望对其他人有所帮助。

按照惯例,您的安装类必须命名为“Setup”,因此您需要重命名AndroidSetupSetup

背景:看Mvvmcross源码,初始化逻辑使用反射和约定来初始化自己。它正在寻找一个名为“Setup”的类。在您的情况下, MvvmCross 找不到您的安装程序类并抛出了您在堆栈跟踪中读取的异常MvvmCross.Exceptions.MvxException: Could not find a Setup class for application


查看完整回答
反对 回复 2022-07-23
  • 1 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号