protected override void OnDestroy() { if (_view != null) { _view.Detach(OnDetachView); _view = null; } if (_networkStatus != null) { _networkStatus.Dispose(); _networkStatus = null; } if (_connections != null) { foreach (var connection in _connections) { UnbindService(connection); } _connections = null; } _service = null; _schedule = null; base.OnDestroy(); }
public RadioStationServiceBinder(RadioStationService service) { Service = service; }
protected override void OnCreate(Bundle savedInstanceState) { if (!string.IsNullOrEmpty(AppCenterConfig.AppSecret)) { AppCenter.Start(AppCenterConfig.AppSecret, typeof(Analytics), typeof(Crashes)); } base.Window.RequestFeature(Android.Views.WindowFeatures.ActionBar); base.SetTheme(Resource.Style.AppTheme); base.OnCreate(savedInstanceState); if (_connections == null) { _connections = new List <IServiceConnection>(); var intent = new Intent(ApplicationContext, typeof(RadioStationService)); var serviceConnection = ServiceConnectionFactory.Create <RadioStationService>(service => { if (service != null) { _service = service; _service.Playing += OnRadioStationPlaying; _service.StateChanged += OnRadioStationStateChanged; _service.Error += OnRadioStationError; } else if (_service != null) { _service.Playing -= OnRadioStationPlaying; _service.StateChanged -= OnRadioStationStateChanged; _service.Error -= OnRadioStationError; _service = null; } }); if (BindService(intent, serviceConnection, Bind.AutoCreate)) { _connections.Add(serviceConnection); } intent = new Intent(ApplicationContext, typeof(RadioStationScheduleService)); var scheduleConnection = ServiceConnectionFactory.Create <RadioStationScheduleService>(service => { if (service != null) { _schedule = service; _schedule.Changed += OnRadioStationScheduleChanged; } else if (_service != null) { _schedule.Changed -= OnRadioStationScheduleChanged; _schedule = null; } }); if (BindService(intent, scheduleConnection, Bind.AutoCreate)) { _connections.Add(scheduleConnection); } } SetContentView(Resource.Layout.MainActivity); if (_view == null) { _view = new MainActivityView(this).Attach(OnAttachView); } if (_networkStatus == null) { _networkStatus = new NetworkStatus(ApplicationContext, connected: OnNetworkConnected, disconnected: OnNetworkDisconnected); } _view.UpdateNetworkStatus(_networkStatus.IsConnected); if (_service != null) { _view.UpdateState(_service.IsPlaying); } if (_schedule != null) { RunOnUiThread(() => _view.UpdateNowPlaying(_schedule.NowPlaying)); } }