How to Pause Acivity when called from another Activity in ANDENGINE

314 Views Asked by At

I have two activities in ANDENGINE . One is ACT_1 and second is ACT_2. Now my ACT_1 is a caller Activity which calls ACT_2.

ACT_1 is my SplashScreen Loader activity. Now after calling ACT_2 from ACT_1 i load some resources and sounds. Its works fine. Now there comes a state that when there is call then the sound/music should stop but the activity's other state should remain the same. For example if acitvity is about some puzzle game then on call puzzle game state remains same and sound should pause and resume on gameresume.I tried OnPauseGame and OnResumeGame in ACT_2 but it is not workinh in ACT_2. But when i call OnResume and OnPause in ACt_1 it calls these function. But Problem is that my ACT_2 starts again.

ACT_1 Activity:

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();
}
0

There are 0 best solutions below