Skip to content

Commit

Permalink
ServiceBindHelper Added
Browse files Browse the repository at this point in the history
  • Loading branch information
umer0586 committed Nov 15, 2022
1 parent 6718cab commit c16f81c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/src/main/java/github/umer0586/service/ServiceBindHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package github.umer0586.service;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;

public class ServiceBindHelper {

private boolean bounded = false;
private Context context;
private ServiceConnection serviceConnection;
private Class service;



public ServiceBindHelper(Context context,ServiceConnection serviceConnection, Class<? extends Service> service)
{
this.context = context;
this.serviceConnection = serviceConnection;
this.service = service;
}

public void bindToService()
{
Intent intent = new Intent(this.context, this.service);
context.bindService(intent, this.serviceConnection, Context.BIND_AUTO_CREATE);
bounded = true;
}

public void unBindFromService()
{
if(bounded)
{
context.unbindService(this.serviceConnection);
bounded = false;
}
}

public void setBounded(boolean bounded)
{
this.bounded = bounded;
}
}

0 comments on commit c16f81c

Please sign in to comment.