Skip to content

Instantly share code, notes, and snippets.

@DanielJette
Last active March 9, 2017 16:00
Show Gist options
  • Save DanielJette/8f982de0d679e5e7cb1dce2716abeb81 to your computer and use it in GitHub Desktop.
Save DanielJette/8f982de0d679e5e7cb1dce2716abeb81 to your computer and use it in GitHub Desktop.
OrientationEventListener to log orientation changes
public abstract class OrientationLoggingActivity extends AppCompatActivity {
private OrientationEventListener orientationEventListener = null;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
orientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int orientation) {
Log.v("OrientationLoggingActivity", "Orientation changed to " + orientation);
}
};
if (orientationEventListener.canDetectOrientation()) {
orientationEventListener.enable();
}
}
@Override
protected void onDestroy() {
orientationEventListener.disable();
orientationEventListener = null;
super.onDestroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment