Chris
Chris

Reputation: 3807

Android Activity bind to Service

I have a series of 3 activities, and the 3rd activity binds (I'm using AIDL) to a Service. What I notice is, if I am on the 3rd activity and start the service, on clicking the back button (moving from 3rd activity to 2nd activity), the Service onDestroy() gets called, and the Service is stopped.

How can I ensure that the service runs even if the Activity is closed?

This is how I bind to the service in the 3rd activity's onCreate method:

this.bindService(new Intent(this,MyService.class), mConnection, Context.BIND_AUTO_CREATE);

Thanks Chris

Upvotes: 0

Views: 1767

Answers (1)

Rich Schuler
Rich Schuler

Reputation: 41972

Use Context#startService. The service will continue to run until stopService is called or the device kills it to free up memory or is killed by the user.

Upvotes: 1

Related Questions