예제 #1
0
        public async void StartBackgroundTask(BackgroundTaskType backgroundTask, BackgroundTaskParameter parameter)
        {
            switch (backgroundTask)
            {
            case BackgroundTaskType.SYNC:
                await Task.Delay(10);

                var    top    = Mvx.IoCProvider.Resolve <IMvxAndroidCurrentTopActivity>();
                Bundle bundle = null;
                if (parameter != null)
                {
                    bundle = new Bundle();
                    bundle.PutInt(SyncBackgroundService.TaskListIdToSyncKey, parameter.SyncOnlyTaskListId);
                }
                top.Activity.StartForegroundServiceCompat <SyncBackgroundService>(bundle);
                break;

            case BackgroundTaskType.ANY:
            case BackgroundTaskType.MARK_AS_COMPLETED:
            default:
                throw new NotSupportedException("The bg task is not supported");
            }
        }
예제 #2
0
        public void StartBackgroundTask(BackgroundTaskType backgroundTask, BackgroundTaskParameter parameter)
        {
            //TODO: HANDLE MULTIPLE BG TASK START, YOU COULD DO IT BY USING APP SETTINGS
            switch (backgroundTask)
            {
            case BackgroundTaskType.ANY:
                throw new ArgumentOutOfRangeException("Its not allowed to start all the bg tasks at the same time");

            case BackgroundTaskType.SYNC:
                if (parameter is null)
                {
                    new SyncBackgroundTask().Run(null);
                }
                else
                {
                    new SyncBackgroundTask(parameter.SyncOnlyTaskListId).Run(null);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException($"Cant start the provided bg task = {backgroundTask}");
            }
        }