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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:33:14+00:00 2026-05-26T21:33:14+00:00

I have an Android app, in which Activities fire long running operations that run

  • 0

I have an Android app, in which Activities fire long running operations that run in the background. These operations interact with the Activities when done. I’m developing a component that handles the Activity/Long-Running-Task coupling, taking care of activities being destroyed and recreated.

Right now that component is implemented as an Android service. The activities call bindService and use the resulting IBinder to start and track tasks. I decided against using startService, because I prefer the richer API possible through a Java interface.

Now the problem. Activity A start ups, binds to the service and calls serviceApi.runTask(…). Activity A is then destroyed (because the user flips the phone, for instance) and recreated as Activity A’. A’ then binds again to the service, announces its existence and everything should be running nicely.

Except that my Service gets destroyed. When Activity A is destroyed, it unbinds from the service. Android sees there are no more clients, and kills the service. When Activity A’ is created, the service is created again, and I lose everything the old service had.

The only solution I can see is using a singleton for the service. And then it doesn’t really have to be an Android service, just an instance that’s accessible to everyone. Is that frowned upon in Android? Is there a better design that fits this problem?


Editted: Even if I call startService and then bind to it, nothing guarantees that the service instance will exist as long as the application is running. Android can kill sticky services if resources are low. Killing the service will cause the application to malfunction, and I can’t have that.

  • 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-26T21:33:14+00:00Added an answer on May 26, 2026 at 9:33 pm

    Even if I call startService and then bind to it, nothing guarantees that the service instance will exist as long as the application is running.

    Correct.

    Android can kill sticky services if resources are low.

    Also correct. All “sticky” means is that Android might restart the service.

    Killing the service will cause the application to malfunction, and I can’t have that.

    It is impossible to create a service that is guaranteed to run forever. For starters, users can get rid of your service whenever they want, because users detest developers who have pointless services that run forever. Writing everlasting services is necessary only in very few cases; otherwise, it’s just sloppy programming.

    The only solution I can see is using a singleton for the service. And then it doesn’t really have to be an Android service, just an instance that’s accessible to everyone. Is that frowned upon in Android?

    Singletons (a.k.a., static data members) will go away when the process is terminated. The process will be terminated eventually, particularly if there are no active services and none of your activities is in the foreground..

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

Sidebar

Related Questions

I have an Android app that I had working a few months ago which
I'm starting an Android app which will have multiple Activities. It will be using
I have an Android app which calculates poker odds ( Shufflebot if you're interested).
I have an android app which gives the user the option of loading a
I have an Android app which includes an activity called Help This uses a
I have made an android app which working fine. I implemented the Login functionality
I have an app which was tested thoroughly and working fine on Android Gingerbread
I have Ripple which im using to test app made for android. App is
I have an Android app project that contains all of my code. I've made
SETUP : I have this app which has 4 activities in a linear path,

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.