Share via


Error : The application may be doing too much work on its main thread

Question

Tuesday, April 2, 2019 1:05 PM

Hey I am building an Xamarin.Android App which reads Sensor data of Accelerometer and displays the Average of x,y,z values. Now I want to compare two different values of two different events and check if the new Value of our average changed for at least a whole integer and if so then it wil be recognized as a new event that will be added to our eventcounter list.

Here is my code:

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]);

    }
}

I do get the following error tho:

04-02 12:52:18.174 I/Choreographer(13407): Skipped 105 frames! The application may be doing too much work on its main thread. 04-02 12:52:18.260 D/EGL_emulation(13407): eglMakeCurrent: 0xa1f05120: ver 3 0 (tinfo 0xa1f03320) 04-02 12:52:19.748 I/Choreographer(13407): Skipped 93 frames! The application may be doing too much work on its main thread. 04-02 12:52:51.408 W/zygote (13407): Checksum mismatch for dex base.apk 04-02 12:52:51.408 W/zygote (13407): Checksum mismatch for dex base.apk 04-02 12:53:00.759 I/zygote (13407): Do partial code cache collection, code=24KB, data=28KB 04-02 12:53:00.761 I/zygote (13407): After code cache collection, code=24KB, data=28KB 04-02 12:53:00.761 I/zygote (13407): Increasing code cache capacity to 128KB ..

Anyone who has faced the same problem?

All replies (2)

Wednesday, April 3, 2019 5:42 AM âś…Answered

In Android, UI events need to happen quickly and if you have a lot of code in your UI events then you will see this error message. Also this will occur with asynchronous events like fetching data from a URL. The solution is to use threads or async tasks.


Wednesday, April 3, 2019 2:34 PM

I have deleted thread.sleep and it works perfectly! Thanks!