Skip to main content

Posts

Showing posts from May, 2017

Servicelib: for reliable Android Services

What is Servicelib?

Setting up Android Services, and binding to them isn't as straightforward as perhaps it could be. Servicelib is a library project that provides you with a number of classes to help simplify these tasks, and configure your service to run reliably in the background.

Android can destroy any Service or Activity at any time to relieve memory constraints - but this Service will hint strongly that the user has an interest in it running uninterrupted, and requests to Android that it restart as soon as conditions are favourable again. The Service will run if any activities are bound to it or not, and will start on boot.

Servicelib also provides you with an abstract Activity class that automatically binds to the Service whenever it is in use, and unbinds when it is not. This gives you access to the Service as if it were just another POJO from your Activities. The Activity can also request permissions for your app, and provides helper methods to determine if all the requi…