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

The Archive Base Latest Questions

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

I read the whole documentation about AsyncTasks, Services,… It’s pretty clear what a remote

  • 0

I read the whole documentation about AsyncTasks, Services,…
It’s pretty clear what a remote Service is for. But I’m having troubles, getting the benefit of a LocalService? The typical example is ‘playing music’ or downloading a big file. But why should I start a local Service for that?

I made a small Async task, simulating such a task.

AsyncTask<String, Integer, String> async = new AsyncTask<String, Integer, String>() {
            @Override
            protected String doInBackground(String... params) {
                for (int i = 0; i < 100; i++) {
                    try {
                        Thread.sleep(500);
                        System.out.println(i);
                    } catch (InterruptedException e1) {
                        e1.printStackTrace();
                    }
                }

                return null;
            }
        };
        async.execute("");

Most answer is, that a (Local)Service is for long running activities, that have to run even when the main activity is closed. OK – but I can do this also with an Async task in the Main Activity:

Button btnFinish = (Button) findViewById(R.id.button1);
        btnFinish.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });

Pressing the button calls onDestroy(), but the Async task is still running? So isn’t that the same like starting the AsyncTask from a Service?

//EDIT:
I ran a couple of tests and I’m pretty sure that the Async Task lives as long as the process does. So if I would wrap it into a local Service (common way) – it would also live as long as the process…

So why does everyone use a local Service for tasks such as downloading files, synchronising,…?!

  • 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-31T09:03:21+00:00Added an answer on May 31, 2026 at 9:03 am

    Most answer is, that a (Local)Service is for long running activities, that have to run even when the main activity is closed. OK – but I can do this also with an Async task in the Main Activity:

    Not without leaking memory. Never leak threads from a component. When an activity is destroyed, ensure all threads started by that activity will be closed quickly.

    I ran a couple of tests and I’m pretty sure that the Async Task lives as long as the process does.

    Correct. However, without a service, the process might live for just a few milliseconds after the user leaves the foreground activity and goes to some other app.

    A service is a marker, telling Android “yo! I’m still doing work here, yo!”. This marker cannot keep the process alive indefinitely, but it usually works well for things that will be running on the order of minutes or hours.

    The service also has its own lifecycle, independent of activities. For example, if you want to get control every 15 minutes to do some work, the proper solution is to use AlarmManager and an IntentService, and there might be no activity of this app around.

    So why does everyone use a local Service for tasks such as downloading files, synchronising

    Because we want it to work properly.

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

Sidebar

Related Questions

I am using csv.reader to read file but it giving me whole file. file_data
Of course, I can explain it in whole books. But I read a few
I've read all of the documentation online about building search interfaces and adding custom
Below i have shared my code in detail. I read documentation and everything about
I'm using jQuery in my web application. While reading its documentation I read about
I've looked on Wikipedia, googled it, and read the official documentation, but I still
While searching for some functions in C++ standard library documentation I read that push
I'd like to read whole content of a text file to a std::string object
Please read the whole question. I'm not looking for an approach to managing multi-lingual
I've read the whole Dragon Book recently (just for fun, I'm not really planning

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.