Skip to content

TannerPerrien/service-connection-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serice Connection Manager

Build Status

Use ServiceConnectionManager to manage Service connections in Android, asynchronously issue commands to a Service before it is connected, and receive Service lifecycle callbacks.

Usage

For each service that you want to manage, create an extension of the service manager:

class MyServiceConnectionManager extends ServiceConnectionManager<MyService, MyServiceBinder> {

  @Override
  protected Class<MyService> getServiceClass() {
    return MyService.class;
  }

}

Then use it in your Activity or Fragment as follows:

class MainActivity extends Activity {

  private MyServiceConnectionManager manager;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // Create the manager
    manager = new MyServiceConnectionManager();

    // Start the manager and connect to the service
    manager.start();

    // Run a command as soon as the service is bound
    manager.runCommand(new ServiceCommand<MyServiceBinder>() {

    @Override
    public void run(MyServiceBinder service) {
      // get something from the service
    }

  }
}

About

A Service manager for Android

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages