Created
May 29, 2018 17:55
-
-
Save mibrahimdev/7131af45af95657b363e9d2dae36aef8 to your computer and use it in GitHub Desktop.
Android architecure components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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