From c16f81c7541e3f504dc6db6385ee32f1cf925ea8 Mon Sep 17 00:00:00 2001 From: umer0586 <35717992+umer0586@users.noreply.github.com> Date: Tue, 15 Nov 2022 22:36:52 +0500 Subject: [PATCH] ServiceBindHelper Added --- .../umer0586/service/ServiceBindHelper.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/src/main/java/github/umer0586/service/ServiceBindHelper.java diff --git a/app/src/main/java/github/umer0586/service/ServiceBindHelper.java b/app/src/main/java/github/umer0586/service/ServiceBindHelper.java new file mode 100644 index 0000000..6430c3f --- /dev/null +++ b/app/src/main/java/github/umer0586/service/ServiceBindHelper.java @@ -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 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; + } +}