Android Async slows down my user interface

I am new to Android app development and have problems with Async tasks. So I am trying to create a graphical ECG application that does some background processing during graphical display.

I defined the following Async task -

private class Erosion extends AsyncTask <Void,Void,Void> {


    @Override
    protected Void doInBackground(Void...unused ) {

        int i,tempIndex;
        double[] tempArray = new double[13];
        double min = ecgSamples[ecgSampleForErosionIndex] - gArray[0]; 
        while (ecgIncoming)
        {
            if (ecgSampleForErosionIndex > 179999)
            {
                ecgSampleForErosionIndex = 0; 
            }

            for(i= 0;i<13;i++)
            {
                tempIndex = ecgSampleForErosionIndex + i; 
                if (tempIndex > 179999)
                {
                    tempIndex =  (ecgSampleForErosionIndex + i) - 180000;
                }
                tempArray[i] = ecgSamples[tempIndex] - gArray[i];
                if (tempArray[i] < min)
                {
                    min = tempArray[i];
                }

            }

            //min needs to be stored in the erosionFirst Array

            if (erosionFirstArrayIndex > 179999)
            {
                erosionFirstArrayIndex = 0; 
            }


            ecgErosion[erosionFirstArrayIndex] = min; 
            erosionFirstArrayIndex++;
            ecgSampleForErosionIndex++;


        }
        return null;


    }

    } //End of Async Task  

So, all I'm trying to do is change the contents of a specific array in an async task - I don't need to update the interface (at least not now)

However, when I run this asynchronous task, my graphical ECG image slows down and becomes a jerk. When I comment on "new Erosion (). Execute ();" the part in the code where I run the Async task, the graphic display becomes normal again.

, ? ?

+5
2

, , , , .

, doInBackground, CPU , . , , , sleep, :

    while (ecgIncoming)
    {
      ... do your thing ...
      Thread.sleep(100); // wait for 100 milliseconds before running another loop
    }

, "100" - , , 1000 ..

+8

new Erosion().execute(); ? , AsyncTask .

0

All Articles