开发者

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, C开发者_如何学运维ontext.BIND_AUTO_CREATE);

Thanks Chris


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜