1582

Android Stop Service on Crash

I am running a Service and am wondering in the rare case that my app crashes will it automatically kill my Service too? I don't want it continuing if this happens.

If not, is there a way to do this such as in the onDestroy() method?

Answer1:

I've done a bit of research, and I think I have a complete answer to your question.

Subclassing Service is fine, assuming you're not using a Remote Service (a Service in a different process.) Assuming your Service is in the same process as your Activity, they'll both end together, in the event of a crash. That being the case, my earlier suggestion to use BoundService wouldn't have actually produced a different result and was based on a flawed understanding of how Application Components work in Android processes.

Quoting from Android bound service - should I manually reconnect in onServiceDisconnected or it tries reconnect automatically:

<strong>Local Service:</strong>

Service is running in the same process as other components (i.e. activity that bound to it) from the same application, when this single application-scoped process has crashed or been killed, it is very likely that all components in this process (include the activity that bound to this service) are also destroyed.

Also, you can read Remote Service Vs. Local Service.

Recommend

  • shaking on 3.0 in a UITableViewController
  • how to map json to java object having a different structure using jackson mixins
  • UIWebView not calling UIScrollViewDelegate methods
  • How to set the javamail path and classpath in windows-64bit “Home Premium”
  • How do I retrieve table names in Cassandra using Java?
  • Cannot install ruby-1.9.2 in Mac OSX 10.8.1 due to symlink error
  • Unable to connect to remote MySql server in Asp.Net
  • How to list all the bucket types in riak?
  • How would you audit ASP.NET Membership tables, while recording what user made the changes?
  • How to convert one data type to another
  • How to modify search result page given by Solr?
  • How to send None with Signals across threads?
  • How To Delete All Words After X Characters
  • Removing event listeners on automatically created multiple elements
  • Can my app be notified when another application starts/stops playing audio?
  • CRASH: *** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 9]
  • Using MouseListener to select a range of cells in a grid
  • Magento get URL before current
  • How to explicitly/implicitly implemented interface members in C++/CLI?
  • Prevent Tomcat from caching request during starup
  • How do I signal completion of my dataflow?
  • How to use JavaScript to determine whether a file exists in a directory?
  • OOP Javascript - Is “get property” method necessary?
  • Is there a way to do normal logging with EureakLog?
  • Content-Length header not returned from Pylons response
  • Cancel a live stream “fast motion” catch-up in Flash
  • Ajax Loaded meta Tags
  • SignalR .NET Client Invoke throws an exception
  • Xamarin Forms - UWP Fonts
  • Azure Cloud Service Web Role web pages do not load
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • How can I estimate amount of memory left with calling System.gc()?
  • Jquery - Jquery Wysiwyg return html as a string
  • Arrays break string types in Julia
  • WPF Applying a trigger on binding failure
  • Hits per day in Google Big Query
  • coudnt use logback because of log4j
  • Java static initializers and reflection