videoplayer在activity被destroy和再次creat之后产生的问题

raphael55 2011-07-18 09:50:53
先说报错
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就会出现上面那个错误。。
求高手帮助
...全文
444 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wabcajs 2011-07-18
  • 打赏
  • 举报
回复
路过 看看...
raphael55 2011-07-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fontlose 的回复:]
Activity内重写onConfigurationChanged方法试试

Java code

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
[/Quote]
好像滑盖时候是没问题了。。我再测试下看看。。感谢大能啊
fontlose 2011-07-18
  • 打赏
  • 举报
回复

Activity内重写onConfigurationChanged方法试试

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
raphael55 2011-07-18
  • 打赏
  • 举报
回复
把滑盖事件给屏蔽掉应该是个不错的方法。。我去找找相关方法
raphael55 2011-07-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 fontlose 的回复:]
比如当横竖屏切换国家地区网络键盘等改变时系统默认会destroy再重新create,当你设android:configChanges="keyboard" 是就告诉系统不用他控制自己来控制当外部按键改变(插入键盘)会自动调用onConfigurationChanged() 方法。

你一个个试试 我看是滑盖操作时把硬件键盘改变了activity加android:configChanges="k……
[/Quote]

试了下,加了这个之后会报android.app.SuperNotCalledException: Activity did not call through to super.onConfigurationChanged()
fontlose 2011-07-18
  • 打赏
  • 举报
回复
比如当横竖屏切换国家地区网络键盘等改变时系统默认会destroy再重新create,当你设android:configChanges="keyboard" 是就告诉系统不用他控制自己来控制当外部按键改变(插入键盘)会自动调用onConfigurationChanged() 方法。

你一个个试试 我看是滑盖操作时把硬件键盘改变了activity加android:configChanges="keyboard|keyboardHidden"看看
fontlose 2011-07-18
  • 打赏
  • 举报
回复
先看下这段AndroidManifest.xml 内<activity>的属性
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.

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧