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

  • Home
  • SEARCH
  • 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 8131349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:04:13+00:00 2026-06-06T09:04:13+00:00

In my android app I am performing some operations in the doInBackground by extending

  • 0

In my android app I am performing some operations in the doInBackground by extending AsyncTask<Void, Void, Void> class. (I have no use in performing any UI in this class)

  1. Is this proper use of AsyncTask ?
  2. If so can I extend AsyncTask instead ?
  3. What is the difference between extending AsyncTask and AsyncTask<Void, Void, Void>

Code example:

public class MessagePooling extends AsyncTask<Void, Void, Void>
{        
    @Override
    protected Void doInBackground(Void... params) 
    {
        while (!isCancelled()) 
        {           
           //Getting data from server            
            SystemClock.sleep(1000);
        }
        return null;
    }
}

Or:

public class MessagePooling extends AsyncTask
{
    @Override
    protected Object doInBackground(Object... params) 
    {
        while (!isCancelled()) 
        {           
           //Getting data from server            
            SystemClock.sleep(1000);
        }
        return null;    
    }
}

Thanks

  • 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-06-06T09:04:16+00:00Added an answer on June 6, 2026 at 9:04 am

    The AsyncTask class can be thought of as a very convenient threading mechanism. It gives you a few tools that you can use that simple Java threads simply don’t have such as on cancel cleanup operations. You don’t have to do any UI in the background. You could simply execute one by writing one as an anonymous class like this:

        new AsyncTask<Integer, Void, Void>(){
            @Override
            protected Void doInBackground(Integer... params) {
                // **Code**
                return null;
            }
        }.execute(1, 2, 3, 4, 5);
    

    It will execute whatever you put in doInBackground on a background thread with the given parameters. Likewise, you can simply use Void and execute with no parameters.

    The only advantage I could think of executing a thread this way would be to aid in future maintenance. There might be a case where you want to modify certain things that are required to be on the UI thread, in which case you would override the other methods. Other cases would be you simply don’t do the action enough to justify writing out another class, so just create one on the fly and be done with it.

    EDIT:

    To answer #3: they’re effectively the same. The Void object is a Java object just like anything else. You’re not using Void, so what you use in it’s place doesn’t matter. It’s just the AsyncTask contract requires three class types to be passed in, and by default they’re Object which is the baseline class of everything.

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

Sidebar

Related Questions

my android app crash before load main.xml. This is the exception thrown java.lang.RuntimeException: Unable
I am new to mobile development, but have some experience with web app development.
This is my first android app and I'm a little disapponted because I'm not
My Android app has a button that executes this code in order to open
We have a webapp performing questionnaire like scans. Entrance point is /app , which
My android app is keep giving me this error. The application has stopped working
I keep trying to use wildcards in a search in an android app, and
My Android app has a layout that looks like this: --------------------- | | |
I have a simple Android RSS reader app in which I am using SAX
import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.Button; public class FileExplorerActivity extends Activity {

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.