先说报错
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): FATAL EXCEPTION: main
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewRoot.setView(ViewRoot.java:514)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.Window$LocalWindowManager.addView(Window.java:424)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.widget.MediaController.show(MediaController.java:304)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.widget.MediaController.show(MediaController.java:249)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.widget.VideoView.toggleMediaControlsVisiblity(VideoView.java:561)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.widget.VideoView.onTouchEvent(VideoView.java:512)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.View.dispatchTouchEvent(View.java:3766)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1720)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1117)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1704)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewRoot.handleMessage(ViewRoot.java:1794)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.os.Looper.loop(Looper.java:143)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.app.ActivityThread.main(ActivityThread.java:4701)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at dalvik.system.NativeStart.main(Native Method)
报错代码:VideoView player = new VideoView(ctx);
MediaController mctrl = new MediaController(ctx);
mctrl.show();
player.setMediaController(mctrl);
player.setVideoURI(url);
player.requestFocus();
player.start();
这是播放一个url视频而已,普通情况测试都ok
只是在滑盖机上,当滑盖操作时,会把整个activity都destroy掉,然后再creat,此时点击player就会出现上面那个错误。。
求高手帮助
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): FATAL EXCEPTION: main
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewRoot.setView(ViewRoot.java:514)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.Window$LocalWindowManager.addView(Window.java:424)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.widget.MediaController.show(MediaController.java:304)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.widget.MediaController.show(MediaController.java:249)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.widget.VideoView.toggleMediaControlsVisiblity(VideoView.java:561)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.widget.VideoView.onTouchEvent(VideoView.java:512)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.View.dispatchTouchEvent(View.java:3766)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1720)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1117)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1704)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.view.ViewRoot.handleMessage(ViewRoot.java:1794)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.os.Looper.loop(Looper.java:143)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at android.app.ActivityThread.main(ActivityThread.java:4701)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-18 09:39:22.759: ERROR/AndroidRuntime(2114): at dalvik.system.NativeStart.main(Native Method)
报错代码:VideoView player = new VideoView(ctx);
MediaController mctrl = new MediaController(ctx);
mctrl.show();
player.setMediaController(mctrl);
player.setVideoURI(url);
player.requestFocus();
player.start();
这是播放一个url视频而已,普通情况测试都ok
只是在滑盖机上,当滑盖操作时,会把整个activity都destroy掉,然后再creat,此时点击player就会出现上面那个错误。。
求高手帮助
android:configChanges
Lists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.
Note: Using this attribute should be avoided and used only as a last-resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.Any or all of the following strings are valid values for this attribute. Multiple values are separated by '|' — for example, "locale|navigation|orientation". Value Description "mcc" The IMSI mobile country code (MCC) has changed — a SIM has been detected and updated the MCC.
"mnc" The IMSI mobile network code (MNC) has changed — a SIM has been detected and updated the MNC.
"locale" The locale has changed — the user has selected a new language that text should be displayed in.
"touchscreen" The touchscreen has changed. (This should never normally happen.)
"keyboard" The keyboard type has changed — for example, the user has plugged in an external keyboard.
"keyboardHidden" The keyboard accessibility has changed — for example, the user has revealed the hardware keyboard.
"navigation" The navigation type (trackball/dpad) has changed. (This should never normally happen.)
"orientation" The screen orientation has changed — the user has rotated the device.
"screenLayout" The screen layout has changed — this might be caused by a different display being activated.
"fontScale" The font scaling factor has changed — the user has selected a new global font size.
"uiMode" The user interface mode has changed — this can be caused when the user places the device into a desk/car dock or when the the night mode changes. See UiModeManager. Introduced in API Level 8.
All of these configuration changes can impact the resource values seen by the application. Therefore, when onConfigurationChanged() is called, it will generally be necessary to again retrieve all resources (including view layouts, drawables, and so on) to correctly handle the change.
试了下,加了这个之后会报android.app.SuperNotCalledException: Activity did not call through to super.onConfigurationChanged()
Activity内重写onConfigurationChanged方法试试@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}