public override void OnCreate() { base.OnCreate(); SensusContext.Current = new AndroidSensusContext { Platform = Platform.Android, MainThreadSynchronizer = new MainConcurrent(), SymmetricEncryption = new SymmetricEncryption(SensusServiceHelper.ENCRYPTION_KEY), CallbackScheduler = new AndroidCallbackScheduler(this), Notifier = new AndroidNotifier(this) }; SensusServiceHelper.Initialize(() => new AndroidSensusServiceHelper()); AndroidSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as AndroidSensusServiceHelper; // we might have failed to create the service helper. it's also happened that the service is created after the // service helper is disposed: https://insights.xamarin.com/app/Sensus-Production/issues/46 if (serviceHelper == null) { Stop(); } else { serviceHelper.SetService(this); } }
public override void OnCreate() { base.OnCreate(); // insights should be initialized first to maximize coverage of exception reporting InsightsInitialization.Initialize(new AndroidInsightsInitializer(Settings.Secure.GetString(ContentResolver, Settings.Secure.AndroidId)), SensusServiceHelper.XAMARIN_INSIGHTS_APP_KEY); SensusContext.Current = new AndroidSensusContext { Platform = Platform.Android, MainThreadSynchronizer = new MainConcurrent(), SymmetricEncryption = new SymmetricEncryption(SensusServiceHelper.ENCRYPTION_KEY), CallbackScheduler = new AndroidCallbackScheduler(this), Notifier = new AndroidNotifier(this) }; SensusServiceHelper.Initialize(() => new AndroidSensusServiceHelper()); AndroidSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as AndroidSensusServiceHelper; // we might have failed to create the service helper. it's also happened that the service is created after the // service helper is disposed: https://insights.xamarin.com/app/Sensus-Production/issues/46 if (serviceHelper == null) { Stop(); } else { serviceHelper.SetService(this); } }
public override void OnCreate() { base.OnCreate(); _serviceHelper = SensusServiceHelper.Get() as AndroidSensusServiceHelper; _serviceHelper.SetService(this); _serviceHelper.UpdateApplicationStatus("0 protocols are running"); }
public override void OnCreate() { base.OnCreate(); SensusServiceHelper.Initialize(() => new AndroidSensusServiceHelper()); _serviceHelper = SensusServiceHelper.Get() as AndroidSensusServiceHelper; // it's happened that the service is created after the service helper is disposed: https://insights.xamarin.com/app/Sensus-Production/issues/46 if (_serviceHelper == null) { StopSelf(); return; } _serviceHelper.SetService(this); _serviceHelper.UpdateApplicationStatus("0 protocols are running"); }
public override void OnCreate() { base.OnCreate(); SensusServiceHelper.Initialize(() => new AndroidSensusServiceHelper()); _serviceHelper = SensusServiceHelper.Get() as AndroidSensusServiceHelper; // it's happened that the service is created after the service helper is disposed: https://insights.xamarin.com/app/Sensus-Production/issues/46 if (_serviceHelper == null) { StopSelf(); return; } _serviceHelper.SetService(this); _serviceHelper.UpdateApplicationStatus("0 protocols are running"); }
public override void OnCreate() { base.OnCreate(); InsightsInitialization.Initialize(new AndroidInsightsInitializer(Settings.Secure.GetString(ContentResolver, Settings.Secure.AndroidId)), SensusServiceHelper.XAMARIN_INSIGHTS_APP_KEY); SensusContext.Current = new AndroidSensusContext(SensusServiceHelper.ENCRYPTION_KEY); SensusServiceHelper.Initialize(() => new AndroidSensusServiceHelper()); AndroidSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as AndroidSensusServiceHelper; // we might have failed to create the service helper. it's also happened that the service is created after the // service helper is disposed: https://insights.xamarin.com/app/Sensus-Production/issues/46 if (serviceHelper == null) { Stop(); } else { serviceHelper.SetService(this); } }
public override void OnDestroy() { Console.Error.WriteLine("--------------------------- Destroying Service ---------------------------"); base.OnDestroy(); AndroidSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as AndroidSensusServiceHelper; // the service helper will be null if we failed to create it within OnCreate, so first check that. also, // OnDestroy can be called either when the user stops Sensus (in Android) and when the system reclaims // the service under memory pressure. in the former case, we'll already have done the notification and // stopping of protocols; however, we have no way to know how we reached OnDestroy, so to cover the latter // case we're going to do the notification and stopping again. this will be duplicative in the case where // the user has stopped sensus. in sum, anything we do below must be safe to run repeatedly. if (serviceHelper != null) { serviceHelper.Logger.Log("Destroying service.", LoggingLevel.Normal, GetType()); NotifyBindingsOfStop(); serviceHelper.StopProtocols(); serviceHelper.SetService(null); } }
public override void OnCreate() { base.OnCreate(); _notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; UpdateNotification("Sensus", ""); _sensusServiceHelper = SensusServiceHelper.Load <AndroidSensusServiceHelper>(new Geolocator(this)) as AndroidSensusServiceHelper; if (_sensusServiceHelper == null) { _sensusServiceHelper = new AndroidSensusServiceHelper(); _sensusServiceHelper.Initialize(new Geolocator(this)); _sensusServiceHelper.Save(); } _sensusServiceHelper.SetService(this); _sensusServiceHelper.Stopped += (o, e) => { _notificationManager.Cancel(SERVICE_NOTIFICATION_ID); StopSelf(); }; }