问题
I do get errors that my code increases the code chache capacity so I have added a delay (Thread.Sleep(1000)) and tried also OnPause which unregisters the Listener.
public void OnSensorChanged(SensorEvent e)
{
lock (_syncLock)
{
newValue = e.Values.Average();
int noteInt1 = Convert.ToInt32(previousValue);
int noteInt2 = Convert.ToInt32(newValue);
try
{
OnPause();
Thread.Sleep(1000);
if (newValue != previousValue)
{
_sensorTextView2.Text = string.Format("Note: {0}", newValue);
eventnumbers.Add(newValue);
}
OnResume();
}
catch (ArgumentNullException)
{
Console.WriteLine(e);
}
}
_sensorTextView.Text = string.Format("x={0:f}, y={1:f}, z={2:f}", e.Values[0], e.Values[1], e.Values[2]);
}
Here is my output
04-02 08:28:11.062 D/Mono (32147): DllImport searching in: '__Internal' ('(null)'). 04-02 08:28:11.062 D/Mono (32147): Searching for 'java_interop_jnienv_new_local_ref'. 04-02 08:28:11.062 D/Mono (32147): Probing 'java_interop_jnienv_new_local_ref'. 04-02 08:28:11.062 D/Mono (32147): Found as 'java_interop_jnienv_new_local_ref'. 04-02 08:28:11.187 I/Choreographer(32147): Skipped 98 frames! The application may be doing too much work on its main thread. 04-02 08:28:11.208 D/EGL_emulation(32147): eglMakeCurrent: 0xa1f050c0: ver 3 0 (tinfo 0xa1f03310) 04-02 08:28:12.519 I/Choreographer(32147): Skipped 79 frames! The application may be doing too much work on its main thread. 04-02 08:28:47.401 W/zygote (32147): Checksum mismatch for dex base.apk
04-02 08:28:47.401 W/zygote (32147): Checksum mismatch for dex base.apk
04-02 08:28:53.370 I/zygote (32147): Do partial code cache collection, code=24KB, data=28KB
04-02 08:28:53.372 I/zygote (32147): After code cache collection, code=24KB, data=28KB
04-02 08:28:53.372 I/zygote (32147): Increasing code cache capacity to 128KB
04-02 08:29:27.411 W/zygote (32147): Checksum mismatch for dex base.apk
04-02 08:29:27.411 W/zygote (32147): Checksum mismatch for dex base.apk
04-02 08:29:35.546 I/zygote (32147): Do partial code cache collection, code=59KB, data=58KB
04-02 08:29:35.546 I/zygote (32147): After code cache collection, code=59KB, data=58KB
04-02 08:29:35.546 I/zygote (32147): Increasing code cache capacity to 256KB
来源:https://stackoverflow.com/questions/55470816/how-do-i-delay-my-sensorlistener-in-onsensorchangedsensorevent-e-method