アクティビティにonPauseがあります。奇妙なことに、その1つのアクティビティ(videoPlayer)でonPauseが2回呼び出されます
シナリオ:これは、電話デバイスのビデオプレーヤーで発生しますが、タブレットでは発生しません。
電源ボタンを押してスタンバイになり、onpauseが呼び出され、次にonresumeが呼び出され、次にonpauseが再度呼び出されます。次に電源ボタンをもう一度押すと、再開時に想定どおりに呼び出されます。
誰かがそのような問題に遭遇したことがありますか?もしそうなら、どのようにそれを修正しましたか?onPause onResume onpauseを設定してから、onResumeの電源をオンにします。
前もって感謝します。これは2回表示されます
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;
}
}
何が起こるかというと、メニューのように外に出ている間一時停止するレコーダーレイアウトのようないくつかのレイアウトの状態を保存します。次に、電源を押すと電源がオフになりますが、電源を入れるとレイアウトがなくなり、ビデオが再生されますが、これは発生しないはずです。