Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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:

Local Service:

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.


Post a Comment for "Android Stop Service On Crash"