Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:21:39+00:00 2026-05-31T01:21:39+00:00

I am new to Android Application development and was having a problem with Async

  • 0

I am new to Android Application development and was having a problem with Async tasks.
So I’m trying to create an ECG graphing application that does some background processing while the graphing is happening.

I’ve 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 modify the content of a particular array in the async task – i dont need to update the UI (at least not for now)

However, when I run this async task my ECG graphing slows down and becomes jerky. When I comment out the “new Erosion().execute();” part in the code where I start the Async task, the graphing becomes normal again.

Isn’t an async task supposed to be on a separate thread and so not affecting how things are happening on my UI thread? What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:21:40+00:00Added an answer on May 31, 2026 at 1:21 am

    Even if you run a heavy piece of code on a background thread it will still affect the CPU load of the device and therefore might cause delays in your UI thread as well, specially if the device has single-core CPU.

    It seems like you have a very heavy loop in you doInBackground method, which runs constantly and just use the CPU nonstop, which overloads it. I’m not sure what this loop is for, but if it doesn’t have to refresh constantly you might want to consider adding a thread sleep, allowing other threads to get more CPU time :

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

    Obviously the “100” is just a number, if the array can update once a second, make it a 1000, etc…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Android development and working on an Android application that requires the
I am very new to Android application development. I successfully added some backgrounds to
I'm new to Android development. I have an application that allows the user to
Im new to Android and Google chrome web application development. I want to create
I'm new to Android Development and am currently trying to develop my first application
I am new in Android Application Development I use the UNION query like that
I'm new to Android application development and I'm currently experimenting with various UI ideas.
I m new to android application development. I made a project on getting feeds
Hello dear programmers, I am very new to android application development and for practice
I am new to android development. I am creating an android application, in which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.