Skip to content

Instantly share code, notes, and snippets.

@shahrukhamd
Created July 5, 2018 17:28
Show Gist options
  • Save shahrukhamd/60542dea9d066872503c985099aa57fc to your computer and use it in GitHub Desktop.
Save shahrukhamd/60542dea9d066872503c985099aa57fc to your computer and use it in GitHub Desktop.
public class ExampleService extends Service {
int mStartMode; // indicates how to behave if the service is killed
IBinder mBinder; // interface for clients that bind
boolean mAllowRebind; // indicates whether onRebind should be used
@Override
public void onCreate() {
// The service is being created
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// The service is starting, due to a call to startService()
return mStartMode;
}
@Override
public IBinder onBind(Intent intent) {
// A client is binding to the service with bindService()
return mBinder;
}
@Override
public boolean onUnbind(Intent intent) {
// All clients have unbound with unbindService()
return mAllowRebind;
}
@Override
public void onRebind(Intent intent) {
// A client is binding to the service with bindService(),
// after onUnbind() has already been called
}
@Override
public void onDestroy() {
// The service is no longer used and is being destroyed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment