Zeburek Zeburek -4 years ago 131
Android Question

Listen on orientation changes

Trying to listen to orientation change in my android program, but nothing works.
My solutions:
Added

android:configChanges="orientation"
to my activity in AndroidManifest
and added this in my Activity class:

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d(TAG_ZT, "Config changed.");
navigation.setSelectedItemId(R.id.navigation_translator);

}


But it doesn't work.

Next my solution was adding:

OrientationEventListener orientationEventListener = new OrientationEventListener(MainActivity.this.getApplicationContext()) {
@Override
public void onOrientationChanged(int orientation) {
Log.d(TAG_ZT, "onOrientationChanged: "+orientation);
navigation.setSelectedItemId(R.id.navigation_translator);
}
};


But also No work.
What I'm doing wrong?

Answer Source

You must be using PPI level 13 or higher. In this case use configChanges="orientation|screenSize" otherwise onConfigurationChanged will not be called.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download