我在 ANDENGINE 有两项活动。一个是 ACT_1,第二个是 ACT_2。现在我的 ACT_1 是调用 ACT_2 的调用者 Activity。
ACT_1 是我的 SplashScreen Loader 活动。现在从 ACT_1 调用 ACT_2 后,我加载了一些资源和声音。它工作正常。现在有一个状态,当有呼叫时,声音/音乐应该停止,但活动的其他状态应该保持不变。例如,如果活动是关于一些益智游戏,那么随叫随到的益智游戏状态保持不变,声音应该在 gameresume 上暂停和恢复。我在 ACT_2 中尝试了 OnPauseGame 和 OnResumeGame,但在 ACT_2 中不起作用。但是当我在 ACt_1 中调用 OnResume 和 OnPause 时,它会调用这些函数。但问题是我的 ACT_2 又开始了。
ACT_1 活动:
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
ACT_2 = new PUZZLE(this, this.mEngine, this.mCamera);
ACT_2.loadSplashSceneResources();
con=this.getApplicationContext();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
pOnCreateSceneCallback.onCreateSceneFinished(eating.createSplashScene());
}
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub
mEngine.registerUpdateHandler(new TimerHandler(1f, new ITimerCallback() {
public void onTimePassed(final TimerHandler pTimerHandler) {
mEngine.unregisterUpdateHandler(pTimerHandler);
ACT_2.loadGameSceneResources();
ACT_2.createGameScenes();
ACT_2.setCurrentScene();
}
}));
pOnPopulateSceneCallback.onPopulateSceneFinished();
}
@Override
public void onResumeGame() {
Log.i("herewwwww","Resume");
super.onResumeGame();
//super.mEngine.start();
//super.mEngine.getMusicManager().setMasterVolume(16);
//super.mEngine.getMusicManager().setMasterVolume(16);
Log.i("Volu",""+super.mEngine.getMusicManager().getMasterVolume());
}
@Override
public void onPauseGame() {
Log.i("herewwwww","Pause");
super.onPauseGame();
//finish();
}
ACT_2
public void onResumeGame() {
Log.i("act_2","resume");
activity.onResumeGame();
this.engine.start();
if(!back_music.isPlaying())
back_music.play();
}
public void onPauseGame() {
Log.i("act_2","pause");
activity.onPauseGame();
if(back_music.isPlaying())
back_music.pause();
}