但当Camera横竖切换时程序运行起来时,抛出如下异常:
android.app.SuperNotCalledException: Activity Camera did not call through to super.onConfigurationChanged()
分析了Android2.3 Camera源码后,是由于在调用重写onConfigurationChanged未立即调用父类方法导致。
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);//这个出了问题,必须在重写后立即调用。
Log.e(TAG, "onConfigurationChanged() config="+config.toString());
PreviewFrameLayout frameLayout =
(PreviewFrameLayout) findViewById(R.id.frame_layout);
frameLayout.setWindowOrientation(config.orientation);
if(config.orientation == WINDOW_ORIENTATION_HORIZENTAL){
if (!mPreviewing && !mStartPreviewFail) {
Log.e(TAG, "!mPreviewing && !mStartPreviewFail onConfigurationChanged");
// resetExposureCompensation();
if (!restartPreview()) return;
}
changeHeadUpDisplayState();
if(!isBusyingNow){
Animation a = mShowZoomBarAnimation;
a.setDuration(300);
rootView.startAnimation(a);
rootView.setVisibility(View.VISIBLE);
}
isScreenLocked=false;
}
// super.onConfigurationChanged(config);//这个出了问题,必须在重写后立即调用,注释掉,然后移动到方法开始。
}
LOG如下:
11-22 11:13:23.376 937 2393 V MediaPlayer: setDataSource(/system/media/audio/ui/VideoRecord.ogg)
11-22 11:13:23.376 937 2393 V MediaPlayerService: Client(11) constructor
11-22 11:13:23.376 937 2393 V MediaPlayerService: Create new client(11) from pid 937, url=/system/media/audio/ui/VideoRecord.ogg, connId=11
11-22 11:13:23.376 937 2393 V MediaPlayerService: setDataSource(/system/media/audio/ui/VideoRecord.ogg)
11-22 11:13:23.376 937 2393 V MediaPlayerService: player type = 3
11-22 11:13:23.376 937 2393 V MediaPlayerService: create VorbisPlayer
11-22 11:13:23.386 937 2393 V MediaPlayerService: setDataSource
11-22 11:13:23.396 937 2393 V MediaPlayer: MediaPlayer::setAudioStreamType
11-22 11:13:23.396 937 2393 V MediaPlayer: prepare
11-22 11:13:23.396 937 2393 V MediaPlayerService: [11] setAudioStreamType(7)
11-22 11:13:23.396 937 2393 V MediaPlayerService: [11] prepareAsync
11-22 11:13:23.396 937 2393 V MediaPlayerService: [11] notify (0xc40e0, 1, 0, 0)
11-22 11:13:23.396 937 2393 V MediaPlayer: message received msg=1, ext1=0, ext2=0
11-22 11:13:23.396 937 2393 V MediaPlayer: prepared
11-22 11:13:23.396 937 2393 V MediaPlayer: signal application thread
11-22 11:13:23.406 937 2393 V MediaPlayer: prepare complete - status=0
11-22 11:13:23.406 2509 2570 E CameraHolder: open camera 1619
11-22 11:13:23.416 2509 2570 E CameraHolder: open done 1630
11-22 11:13:23.416 2509 2570 E camera : CameraHolder.instance().open() time=1631
11-22 11:13:23.426 2509 2570 E camera : mCameraDevice.getParameters() time=1640
11-22 11:13:23.426 2509 2570 D Camera : app passed NULL surface
11-22 11:13:23.436 2509 2570 E setCameraParameters(): setCameraParameters............updateSet=-1
11-22 11:13:23.436 2509 2570 E camera : updateCameraParametersInitialize()
11-22 11:13:23.436 2509 2570 E camera : updateCameraParametersZoom()
11-22 11:13:23.436 2509 2570 E camera : mZoomValue=0
11-22 11:13:23.436 2509 2570 E camera : updateCameraParametersPreference()
11-22 11:13:23.446 2509 2570 E camera : updateCameraParametersPreference()
11-22 11:13:23.446 2509 2570 E ComboPreferences: mPrefLocal.getString(key, defValue);
11-22 11:13:23.446 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.446 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.456 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.456 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.456 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.456 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.456 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.456 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.456 2509 2570 E ComboPreferences: mPrefGlobal.getString(key, defValue)
11-22 11:13:23.466 2509 2570 E ComboPreferences: mPrefLocal.getString(key, defValue);
11-22 11:13:23.466 2509 2570 E setCameraParameters(): setCameraParameters...ok!
11-22 11:13:23.466 937 2393 D CameraHardwareComip: preview xoffset: 25, preview yoffset: 5
11-22 11:13:23.466 937 2393 D CameraHardwareComip: window width: 258, window height: 194
11-22 11:13:23.488 937 2393 D CameraHardwareComip: picture width: 2048, picture height: 1536, fps: 30
11-22 11:13:23.488 937 2393 E CameraHardwareComip: overlayConfig: Overlay is not set yet
11-22 11:13:23.496 2509 2570 E camera : max-zoom=0
11-22 11:13:23.496 2509 2570 E camera : mZoomValue=0
11-22 11:13:23.506 2509 2570 V camera : startPreview
11-22 11:13:23.516 937 1273 D CameraHardwareComip: startPreview: 0x0
11-22 11:13:23.610 937 1273 D CameraHardwareComip: zoom(0): 100
11-22 11:13:23.657 937 1273 W CameraHardwareComip: camera device don't support brightness
11-22 11:13:23.686 937 1273 D CameraHardwareComip: streamOn: 0
11-22 11:13:23.697 937 1273 D CameraHardwareComip: overlayDisplay : 1
11-22 11:13:23.996 2509 2509 E CameraHolder: Camera occupied
11-22 11:13:24.066 2509 2509 D AndroidRuntime: Shutting down VM
11-22 11:13:24.076 2509 2509 W dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4001d7d8)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: FATAL EXCEPTION: main
11-22 11:13:24.076 2509 2509 E AndroidRuntime: android.app.SuperNotCalledException: Activity Camera did not call through to super.onConfigurationChanged()
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:3928)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:4017)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2106)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at android.os.Looper.loop(Looper.java:123)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4627)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:521)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-22 11:13:24.076 2509 2509 E AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
11-22 11:13:24.106 1247 1250 W ActivityManager: Force finishing activity com.android.camera/.Camera