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 7549393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:56:19+00:00 2026-05-30T09:56:19+00:00

In one Activity , I have 2 heavy tasks. One is a creation of

  • 0

In one Activity, I have 2 heavy tasks. One is a creation of the default database with default rows and values. The other one is fetching all data from the database to populate UI elements on the screen. There are over 100 UI elements on that page (statistical data).

Now, would it be bad to have two AsyncTask classes in one Java code file? One would be used to create default database (activated only on first start) and the other one would be used a lot of times to fetch all data from the database needed to populate the afore mentioned UI elements.

I am asking about bad practice and not about the fact whether the same AsyncTask class could be used for both heavy tasks (via if/else).

  • 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-30T09:56:20+00:00Added an answer on May 30, 2026 at 9:56 am

    Nope. Don’t think so. How else would you do two background tasks ?

    I would recommend however that for code clarity you use a design pattern whereby the result of the background tasks is differentiated in the same method using request codes that you send to the AsyncTask.

    Something like:

    new AsyncTask1(this, 0).execute();
    new AsyncTask2(this, 1).execute();
    

    The AsyncTask can then call back the same method in the Activity and you can differentiate on the basis of the request code.

    onBackgroundTaskCompleted(int requestCode, Object result) {
        if (requestCode == 0 ) {
            // do something
        } else {
            // do something else
        }
    

    For an example of using this pattern using interface have a look at the async classes at : https://github.com/sfarooq/A-droid-lib/

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

Sidebar

Related Questions

I have one activity which download data from the web. In middle of the
i have two Activity in this i take pixels of image from one activity
I am using fragments to show images/pages.I have one Activity(Main) which contains all the
I have one activity which can be open from more 4 or 5 different
I have one activity Select which has four buttons and other activity Result. Now
I have to include one report in my application showing offline/online activity of few
I've more than one activity (inside the same Application) that needs to have access
I have in one activity (firstactivity): ArrayList <MyDouble> myfinals=new ArrayList <MyDouble>(); ... i.putParcelableArrayListExtra(myfinals,myfinals); ...
I need to have a class with one activity that is performed once per
I have an app, one activity is a form with multiple fields. In landscape

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.