我为清单文件中的活动添加了android:configChanges =“ density”。但是我没有收到onConfigurationChanged()回调
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ClientActivity" android:configChanges="density">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我在下面提到了onConfigurationChanged()方法。其实我在那个里面什么也没做。如果我回电,我想继续进行下去。
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
答案 0 :(得分:1)
添加清单
android:configChanges="keyboardHidden|orientation|screenSize"
添加活动。
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Log.d("OrientationMyApp", "Current Orientation : Landscape");
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Log.d("OrientationMyApp", "Current Orientation : Portrait");
// Your magic here for portrait mode
}
}