Skip to content

Instantly share code, notes, and snippets.

@mibrahimdev
Created May 29, 2018 17:55
Show Gist options
  • Save mibrahimdev/7131af45af95657b363e9d2dae36aef8 to your computer and use it in GitHub Desktop.
Save mibrahimdev/7131af45af95657b363e9d2dae36aef8 to your computer and use it in GitHub Desktop.
Android architecure components
public class BoundLocationManager {
public static void bindLocationListenerIn(LifecycleOwner lifecycleOwner, LocationListener listener, Context context) {
new BoundLocationListener(lifecycleOwner, listener, context);
}
@SuppressWarnings("MissingPermission")
static class BoundLocationListener implements LifecycleObserver {
...
public BoundLocationListener(LifecycleOwner lifecycleOwner, LocationListener listener, Context context) {
...
// add this class as an observer of the passed lifecycleOwner
lifecycleOwner.getLifecycle().addObserver(this);
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
void addLocationListener() {
//some implementation
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
void removeLocationListener() {
//some implementation
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment