Skip to content

Instantly share code, notes, and snippets.

@daeun1012
Created December 1, 2017 01:58
Show Gist options
  • Save daeun1012/3e35341b45011f7794188cb057a2b340 to your computer and use it in GitHub Desktop.
Save daeun1012/3e35341b45011f7794188cb057a2b340 to your computer and use it in GitHub Desktop.
class MyLocationListener {
public MyLocationListener(Context context, Callback callback) {
// ...
}
void start() {
// connect to system location service
}
void stop() {
// disconnect from system location service
}
}
class MyActivity extends AppCompatActivity {
private MyLocationListener myLocationListener;
@Override
public void onCreate(...) {
myLocationListener = new MyLocationListener(this, (location) -> {
// update UI
});
}
@Override
public void onStart() {
super.onStart();
myLocationListener.start();
// manage other components that need to respond
// to the activity lifecycle
}
@Override
public void onStop() {
super.onStop();
myLocationListener.stop();
// manage other components that need to respond
// to the activity lifecycle
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment