[英]onBackPress() is not working when app comes to foreground from background
I have a videoView in my activity.我的活动中有一个 videoView。 onBackPress() is not working when app comes to foreground from background and also when i lock my phone and unlock it because of videoView.seekTo(1).当应用程序从后台进入前台以及由于 videoView.seekTo(1) 而锁定我的手机并解锁它时,onBackPress() 不起作用。 How do we solve it我们如何解决它
Below is my code.下面是我的代码。 Please help请帮忙
public class VideoPreviewActivity extends implements View.OnClickListener {
TextView tv_response;
ImageView iv_video_preview;
VideoView videoView;
@SuppressLint({"ClickableViewAccessibility", "InlinedApi"})
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_preview);
processIntent(getIntent());
}
public void processIntent(Intent intent) {
int is_doc_context = intent.getIntExtra(IS_DOC_CONTEXT, 2);
if (is_doc_context == 1) {
final MediaController mc = new MediaController(this);
mc.setVisibility(View.GONE);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
final Uri video = Uri.parse(videoFileString);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.seekTo( 1 );
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
}
});
}
}
@Override
protected void onResume() {
videoView.seekTo( 1 );
super.onResume();
}
@Override
protected void onPause() {
if (videoView.isPlaying()){
videoView.stopPlayback();
}
super.onPause();
}
@Override
public void onBackPressed() {
LibUtils.onBackButtonClick(VideoPreviewActivity.this);
}
}
Please let me know if you need any information.如果您需要任何信息,请告诉我。
call super.onBackPressed() inside in your override onBackPressed() method.在您的覆盖 onBackPressed() 方法中调用 super.onBackPressed() 内部。
You didn't call findViewById
for videoView
.您没有为videoView
调用findViewById
。
1) Make sure that in your xml
of videoView
you add an id
: 1) 确保在xml
的videoView
中添加一个id
:
<VideoView
android:id="@+id/video_view"
android:layout_height="......"
android:layout_width="......." />
2) Do this in onCreate()
: 2) 在onCreate()
中执行此操作:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_preview);
processIntent(getIntent());
//here find the video view
videoView = findViewById(R.id.video_view);
}
3) One more thing in your onBackPressed()
: 3)在你的onBackPressed()
中还有一件事:
@Override
public void onBackPressed() {
LibUtils.onBackButtonClick(VideoPreviewActivity.this);
//add this
super.onBackPressed();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.