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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:18:32+00:00 2026-06-13T03:18:32+00:00

I’m trying to write a simple Service that will do something every few seconds.

  • 0

I’m trying to write a simple Service that will do something every few seconds. But when I run the Service while trying to run other AsyncTasks in the main Activity, I noticed that the other AsyncTasks get stuck at onPreExecute. When I disabled the service, everything worked as expected. Is there a reason why the Service’s AsynTask is blocking the other AsyncTasks?

Service

public class SVC_SyncData extends Service {

    private final String TAG = "SVC_SyncData";

    private AT_SyncData m_SyncPoll = null;

    public static boolean isRunning = false;

    public SVC_SyncData() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "onCreate");
        m_SyncPoll = new AT_SyncData(this);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand");
        m_SyncPoll.execute();
        isRunning = true;
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy");
        m_SyncPoll.cancel(false);
        isRunning = false;
    }
}

AT_SyncData’s doInBackground

@Override
protected Void doInBackground(Void... params) {
    Log.i(TAG, "doInBackground");

    try {
        while (!isCancelled()) {
            Log.i(TAG, "syncData");

            // Sleep until next cycle
            Thread.sleep(5000);
        }
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }

    return null;
}
  • 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-13T03:18:33+00:00Added an answer on June 13, 2026 at 3:18 am

    The AsyncTask documentation states:

    Order of execution

    When first introduced, AsyncTasks were executed serially on a single
    background thread. Starting with DONUT, this was changed to a pool of
    threads allowing multiple tasks to operate in parallel. Starting with
    HONEYCOMB, tasks are executed on a single thread to avoid common
    application errors caused by parallel execution.

    If you truly want parallel execution, you can invoke
    executeOnExecutor(java.util.concurrent.Executor, Object[]) with
    THREAD_POOL_EXECUTOR.

    Thus, newer versions of android will have this problem you describe. You need to use executeOnExecutor to make sure that you are running on separate threads.

    Furthermore, if you have service that you want to run in a separate thread I recommend either:

    1. Use an IntentService
    2. Sometimes you will want more control over your service’s lifecycle than what IntentService gives you, in those cases you can just create a thread in the service and run your background code in that. Actually, to be more specific, create a HandlerThread which includes a Looper so you can use the standard android method for communication (messages) between your main thread and the background thread. Personally, I usually choose this option for my services.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.