How do I delay my SensorListener in onSensorChanged(SensorEvent e) method?

痴心易碎 提交于 2019-12-08 12:08:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!