我的活动正在进行中.奇怪的是,仅在单个活动(一个videoPlayer)中,onPause就会被调用两次
场景:
这是在手机设备上的视频播放器中发生的,而平板电脑上没有.
按电源按钮进入待机状态,先叫onpause,再叫onresume,然后再叫停顿.然后再按一次电源按钮,就可以像预期那样调用简历了.
有没有人遇到过这样的问题,如果是这样,您如何解决它.即使只是onPause onResume onpause,然后再打开onResume.
提前致谢.
这个出现两次
protected void onPause()
{
Log.i("VideoPlayer", "onPauseCalled");
super.onPause();
pauseMedia();
Log.i("onPause", " save states to be called");
if(saveAllowed)
saveStates();
Log.i("onPause", " save States called");
view.setVisibility(View.GONE);
//Log.i("onPause", "visibility GOne");
removeListeners();
doCleanUp();
}
@Override
protected void onResume()
{
super.onResume();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
Log.i("VideoPlayer", "onResumeCalled");
if(pm.isScreenOn())
{
//Initialization
initializeViewControls();
handler = new Handler();
initializeButtons();
initRecordButtons();
initVolumeControl();
//RestoreState
restoreMediaBoolean();
restoreMediaState();
Log.i("After", "restoreState");
view = (SurfaceView) findViewById(R.id.surfaceView);
//Log.i("After", "GettingView");
holder = view.getHolder();
view.setVisibility(View.VISIBLE);
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Log.i("onResume", "view is Visible");
saveAllowed = true;
}
else
saveAllowed = false;
}
private void saveStates()
{
if(!isFinishing)
{
//Log.i("VideoPlayer", "Called at saveStates()");
prefs = getSharedPreferences(PREF_SAVE, Context.MODE_PRIVATE);
if(prefs != null)
{
prefEditor = prefs.edit();
}
if(prefEditor != null)
{
//Save overlay visibiltiy
if((volumeLayout != null) && (volumeLayout.getVisibility() == View.VISIBLE))
{
prefEditor.putBoolean(IS_VOLUME_VISIBLE, true);
prefEditor.commit();
}
else
{
prefEditor.putBoolean(IS_VOLUME_VISIBLE, false);
prefEditor.commit();
}
//Save recorder Overlay state
if((recordLayout != null) && (recordLayout.getVisibility() == View.VISIBLE) )
{
prefEditor.putBoolean(IS_RECORDER_VISIBLE, true);
prefEditor.commit();
}
else
{
prefEditor.putBoolean(IS_RECORDER_VISIBLE, false);
prefEditor.commit();
}
//Save controller OVerlay State
if((backButton != null) && (backButton.getVisibility() == View.VISIBLE))
{
prefEditor.putBoolean(IS_CONTROLLER_VISIBLE, true);
prefEditor.commit();
Log.i("Save States", "Controller saved as visible");
}
else
{
Log.i("Save States", "Controller saved as Invisible");
//Log.i("Saving", "Controller Invisible");
prefEditor.putBoolean(IS_CONTROLLER_VISIBLE, false);
prefEditor.commit();
}
//Save is private Audio Recorded
prefEditor.putBoolean(IS_PRIVATE_AUDIO_RECORDED, isCustomVoiceRecorded);
prefEditor.commit();
//Save are we playing out custom audio
prefEditor.putBoolean(PLAY_CUSTOM_AUDIO, playCustomAudio);
prefEditor.commit();
//Make boolean is restoring
prefEditor.putBoolean(IS_RESTORING, true);
prefEditor.commit();
//Saves Position of Current Video
if(vidplayer != null)
{
prefEditor.putInt(VIDEO_POSITION, videoPausedAt);
prefEditor.commit();
}
//Save Position of Current Audio
if(audplayer != null)
{
prefEditor.putInt(AUDIO_POSITION, audioPausedAt);
prefEditor.commit();
}
prefEditor = null;
prefs = null;
}
}
发生的是,我保存了某些布局的状态,例如记录器布局,当它有点像菜单时会暂停.然后,如果按下电源,它会关闭,但重新打开时,布局就消失了,视频正在播放,这是不应该发生的.
解决方法:
是的,我有类似的问题.您使用的是哪个设备(如果为我正确提供内存,我认为这是NFC屏幕超时问题)?暂停对我来说不是问题,但我尝试在onResume(被调用两次)中恢复视频,因此我在onResume中使用了以下内容:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (pm.isScreenOn()) {
//now do stuff
}
标签:onpause,onresume,android 来源: https://codeday.me/bug/20191201/2079295.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。