问题
I have a VideoView
in one of my Activities
and if I try to press the back Button
it doesn't take me to the previous Activity
and it doesn't give any error messages in the log cat either.
I have tried overriding the onBackPressed()
method and I have tried calling the prev Activity
using an Intent
, but even then the back Button
didn't do anything.
This problem only occurs when the video is playing and even after it is finished playing. The only time the back Button
works is before the video starts playing. My VideoView
also has a MediaController
set to it.
Any ideas ?
Thanks!
回答1:
From CommansWare
Based on the source code, this should work:
- Extend MediaController (for the purposes of this answer, call it RonnieMediaController)
- Override dispatchKeyEvent() in RonnieMediaController
- Before chaining to the superclass, check for KeyEvent.KEYCODE_BACK, and if that is encountered, tell your activity to finish()
- Use RonnieMediaController instead of MediaController with your VideoView
Personally, I'd just leave it alone, as with this change your user cannot make a RonnieMediaController disappear on demand.
Here is the link to the original post.
来源:https://stackoverflow.com/questions/11779692/back-button-wont-work-when-videoview-is-playing-video