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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:00:23+00:00 2026-06-16T21:00:23+00:00

I have a class that implements fileuploader service. Activites bind to it and supply

  • 0
  1. I have a class that implements fileuploader service. Activites bind to it and supply it a list of files to be uploaded, and then unbind immediately. The files are then uploaded one-by-one by the service in a background thread(asynctask).

  2. I start this service in my dashboard actvity using startService(), so that it keeps running until specifically stopService() is called.

  3. Now, my question is when do I stop this service?

Basically I need to check two conditions: 1: all files are uploaded; 2: app has exited.
Also, to exit the App, user has to press back button on dashboard activity.

I could have overrided back button press and queriesd the service whether any files are left, but I dont want to use that method.

Any suggestions?

  • 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-16T21:00:24+00:00Added an answer on June 16, 2026 at 9:00 pm

    Activites bind to it and supply it a list of files to be uploaded, and then unbind immediately.

    I would recommend then using startService() rather than bindService().

    The files are then uploaded one-by-one by the service in a background thread(asynctask).

    This seems like a much better fit for startService() and an IntentService (or a WakefulIntentService perhaps, if you are concerned about the device falling asleep during uploads).

    I start this service in my dashboard actvity using startService()

    This would not be needed if you used startService() for sending over the work.

    so that it keeps running until specifically stopService() is called.

    Ideally, the service would shut itself down, like IntentService does. After all, only the service knows when the service is done.

    my question is when do I stop this service?

    When you have no more work to do. IntentService does this automatically. If you really want to maintain your own thread pool for doing the work, then when your work queue is empty and all threads are done, call stopSelf() from within the service.

    Basically I need to check two conditions: 1: all files are uploaded

    Yes.

    2: app has exited

    No. Your UI should not care whether the service is running or not running. The service should take care of itself.

    Also, to exit the App, user has to press back button on dashboard activity.

    Users are welcome to leave your app however they please: BACK, HOME, RECENTS, a Notification, an incoming phone call, etc.

    Any suggestions?

    Use an IntentService. Send over the jobs to be uploaded via calls to startService(), packaging all needed data into the Intent used with startService() (e.g., extras). Do your upload work in onHandleIntent(). If desired, use LocalBroadcastManager to let activities in your app know about the upload status, so they can reflect that in their UI if they so choose. IntentService will handle stopping itself when its work queue empties.

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

Sidebar

Related Questions

I have a class that implements a linked list. The class has a find()
I have a class that implements the IDisposable interface. I am using a webclient
I have a class that implements properties in a specific way, to handle some
I have a class that implements IComparable. public class MyClass : IComparable<MyClass> { public
I have a class that implements InvocationHandler as below: public class MyProxyClass implements InvocationHandler
When I have a class that implements INotifyPropertyChanged, is it ok to expose the
Context: I have a class that implements a Session, maintaining a TCP connection to
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Given: I have an interface. I have only class that implements that interface. Question:
I have an abstract class that implements IDisposable, like so: public abstract class ConnectionAccessor

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.