internal static void PlatformStart() { if (context == null) { throw new InvalidOperationException("Background service is not initialized yet"); } var intent = new Intent(context, typeof(BackgroundService)); context.StartService(intent); }
public static void StartServer(ContextWrapper context, Intent intent) { if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { context.StartForegroundService(intent); } else { context.StartService(intent); } }
public static void Init(ContextWrapper context) { MessagingCenter.Subscribe <StartLongRunningTask>(context, nameof(StartLongRunningTask), message => { var intent = new Intent(context, typeof(BackgroundService)); context.StartService(intent); }); MessagingCenter.Subscribe <StopLongRunningTask>(context, nameof(StopLongRunningTask), message => { var intent = new Intent(context, typeof(BackgroundService)); context.StopService(intent); }); }
public static ServiceToken BindToService(Context context, IServiceConnection connection) { var activity = ((Activity)context).Parent; if (activity is null) { activity = (Activity)context; } var wrapper = new ContextWrapper(activity); wrapper.StartService(new Intent(wrapper, typeof(MusicService))); var conn = new ServiceConnection(connection); if (wrapper.BindService(new Intent(wrapper, typeof(MusicService)), conn, 0)) { _connectionMap.Add(wrapper, conn); return(new ServiceToken(wrapper)); } return(null); }