title: How to recognize Event with onSensorChanged by comparing two float values
body: <p>I want to read data from my Accelerometer Sensor and compare them if the first number of the float changes. I have some problem to unregister the listener or pause in order to compare and see if the average/Note has increased by a full Int for example "Note: 5.677" increases to "Note:6.234" then it supposed to be recognized as an event. </p>
  
  <p>I have converted them into Ints so I can check if they are equal or not.<br>
  I already have tried to delay it with Thread.Sleep and pause but doesnt work.
  Maybe because of Lock(_synlock) ?</p>
  
  <pre><code>public void OnSensorChanged(SensorEvent e)
          {
              lock (_syncLock)
              {
                  avg = e.Values.Average();
                  _sensorTextView.Text = string.Format("x={0:f}, y={1:f}, z={2:f}", e.Values[0], e.Values[1], e.Values[2]);
                  _sensorTextView2.Text = string.Format("Note: {0}", avg);
                  note1 = e.Values.Average();
  
                  //Thread.Sleep(500);
                  //base.OnPause();
                  //_sensorManager.UnregisterListener(this);
                  //base.OnResume();
                  //_sensorManager.RegisterListener(this, _sensorManager.GetDefaultSensor(SensorType.Accelerometer), SensorDelay.Ui);
  
  
                  //_sensorTextView.Text = string.Format("x={0:f}, y={1:f}, z={2:f}", e.Values[0], e.Values[1], e.Values[2]);
                  //avg = e.Values.Average();
                  //_sensorTextView2.Text = string.Format("Note: {0}", avg);
                  //note2 = e.Values.Average();
              }
              int noteInt1 = Convert.ToInt32(note1);
              int noteInt2 = Convert.ToInt32(note2);
  
              //Thread.Sleep(2000); "zeige alle 2 sekunden an" 
              List&lt;double&gt; eventnumbers = new List&lt;double&gt; { };
              if (noteInt1 != noteInt2)
                  {
                  avg = e.Values.Average();       
                  //Console.WriteLine("bye");
                  _sensorTextView2.Text = string.Format("Note: {0}", avg);
                  //foreach(SensorEvent e){
                  eventnumbers.Add(new double()); //Value of avg is the value of the eventnumber element
                  eventnumbers.ForEach(Console.WriteLine);
                  }
  
              }
  </code></pre>
  
  <p>UPDATE :</p>
  
  <pre><code> public void OnSensorChanged(SensorEvent e)
          {
              lock (_syncLock)
              {
                  _sensorTextView.Text = string.Format("x={0:f}, y={1:f}, y={2:f}", e.Values[0], e.Values[1], e.Values[2]);
                  //_sensorTextView2.Text = string.Format("Note: {0}", e.Values.Average());
                  avg = e.Values.Average();
              }
              eventCounter();
          }
          public void eventCounter()
          {
  
              eventnumbers.Add(avg);          //add number to our buffer
              Console.WriteLine(avg);
  
              eventnumbers.Add(avg+1);       //adding a number different of our first one to see if the method works    
              Console.WriteLine(avg+1);
  
  
  
              while (eventnumbers.Count &gt;= 1)     //as long as two elements included
              {
                  for (int puffer = 0; puffer &lt;= 10; puffer++)    //buffer of 10 Elements
                  {
                      for (int i = 0; i &lt; eventnumbers.Count; i++)    //compare first number of our buffer
                      {
                          note1 = eventnumbers[i];    //remember value of first element
                          Console.WriteLine(note1);
                          Console.WriteLine("i ist:" + i);
  
  
                          for (int j = 1; j &lt;= eventnumbers.Count; j++)   //with the second number of our buffer
                          {
                              Console.WriteLine("j ist:" + j);
                              note2 = eventnumbers[j];    //remember value of second element
                              Console.WriteLine(note2);
                          }
                      }
                          while (eventnumbers.Count &gt;= 1) //as long as two elements included
                          {
                                  try
                                  {
  
                                      noteInt1 = Convert.ToInt32(note1);  //double to Int 
                                      noteInt2 = Convert.ToInt32(note2);
  
                                      if (noteInt1 != noteInt2) //we parse to int in order to compare if event has changed
                                      {
                                          _sensorTextView2.Text = string.Format("Note: {0}", avg); //if yes update our displaying mark/number
                                          eventcounters.Add(avg);                     //add element to elementcounter
  
                                      }
                                      break;              //
                                  }
  
                                  catch (System.ArgumentOutOfRangeException)      //for the case if there are less than 2 elements to compare
                                  {
                                      eventcounters.ForEach(Console.WriteLine);   //return all marks(numbers) from our eventcounter
  
                                  }
                                  break;
                              } break;
  
                          }
  
                      //throw new NotImplementedException();
                  }
                  eventnumbers.Clear();
              }
  </code></pre>
  
  <p>My Problem is that I do not get another (different) value when I call e.Value.Average(). I need to do it outside the method and call onSensorChanged another time but i dont know how to do that since I need to create another event, right? thats why I have used e1 and e2 but I think I miss something with the initialization i guess.</p>
  
  <p>This is how I have tried so far creating two events:</p>
  
  <pre><code>public class MainActivity : Activity, ISensorEventListener
      {
          static readonly object _syncLock = new Object();
          SensorManager _sensorManager;
          TextView _sensorTextView;
          TextView _sensorTextView2;
          double note1;
          double note2;
          double avg;
          SensorEvent e1;
          SensorEvent e2;
  </code></pre>
  
  <p>my one create():</p>
  
  <pre><code>protected override void OnCreate(Bundle bundle)
          {
              base.OnCreate(bundle);
              SetContentView(Resource.Layout.activity_main);
              _sensorManager = (SensorManager)GetSystemService(SensorService);
              _sensorTextView = FindViewById&lt;TextView&gt;(Resource.Id.accelerometer_text);
              _sensorTextView2 = FindViewById&lt;TextView&gt;(Resource.Id.accelerometer_note);
              e1 = (SensorEvent)GetSystemService(ISensorEventListener);
              e2 = (SensorEvent)GetSystemService(ISensorEventListener);
              displayMark();
  </code></pre>
  
  <p>ISensorEventListener is marked a wrong btw</p>
  
  <pre><code>public void displayMark()
          {
  
              OnSensorChanged(e1);
              note1 = e1.Values.Average();
  
              OnSensorChanged(e2);
              note2 = e2.Values.Average();
  
  
              int noteInt1 = Convert.ToInt32(note1);
              int noteInt2 = Convert.ToInt32(note2);
              Console.WriteLine(noteInt1);
              Console.WriteLine(noteInt2);
  
              List&lt;double&gt; eventnumbers = new List&lt;double&gt; { };
              if (noteInt1 != noteInt2)
              {
                  avg = e2.Values.Average();
                  Console.WriteLine("bye");
                  _sensorTextView2.Text = string.Format("Note: {0}", avg);
                  //foreach(SensorEvent e){
                  eventnumbers.Add(new double()); //Value of avg is the value of the eventnumber element
              }
              eventnumbers.ForEach(Console.WriteLine);
  </code></pre>