Ejemplo n.º 1
0
 /// <summary>
 /// SensorCore needs to be deactivated when app goes to background
 /// </summary>
 public async Task DeactivateAsync()
 {
     _sensorActive = false;
     if (_stepCounter != null)
     {
         await _stepCounter.DeactivateAsync();
     }
 }
Ejemplo n.º 2
0
 protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e)
 {
     if (_pollTimer != null)
     {
         _pollTimer.Stop();
     }
     if (_stepCounter != null)
     {
         await _stepCounter.DeactivateAsync();
     }
 }
Ejemplo n.º 3
0
        public MainPage()
        {
            this.InitializeComponent();
            this.NavigationCacheMode = NavigationCacheMode.Required;

            Window.Current.VisibilityChanged += async(oo, ee) =>
            {
                if (ee.Visible)
                {
                    if (await CallSensorcoreApiAsync(async() =>
                    {
                        if (_stepCounter == null)
                        {
                            // Get sensor instance if needed...
                            _stepCounter = await StepCounter.GetDefaultAsync();
                        }
                        else
                        {
                            // ... otherwise just activate it
                            await _stepCounter.ActivateAsync();
                        }
                    }))
                    {
                        // Display current reading whenever application is brought to foreground
                        await ShowCurrentReading();
                    }
                }
                else
                {
                    // Sensor needs to be deactivated when application is put to background
                    if (_stepCounter != null)
                    {
                        await CallSensorcoreApiAsync(async() => await _stepCounter.DeactivateAsync());
                    }
                }
            };
        }