0

I'm developing a game in android and i have an extrange bug. When I execute the app first time all runs ok, but when I press the home button an then I return to app the screen stills white, using Log I can see that the onResume() isn't called. When I press home button the onPause() method is called.

public class MainActivity extends Activity {
GameView gV;
public static final String PREFS_NAME = "ShNCoPrefs";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    gV=new GameView(this);
    setContentView(gV);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    // Restore preferences
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    boolean isFirstPlay = settings.getBoolean("isFirstPlay", true);
    gV.setFirstPlay(isFirstPlay);



}

@Override
public void onResume(){
    super.onResume();
    Log.i("onResume", "main-pasó por aquí 1");
    if (gV.thread!=null)
    gV.runThread();
    Log.i("onResume", "main-pasó por aquí 2");


}

@Override
public void onPause(){
    super.onPause();
     SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
     SharedPreferences.Editor editor = settings.edit();
     editor.putBoolean("isFirstPlay", gV.isFirstPlay());

  // Commit the edits!
     editor.commit();
  if(gV.thread!=null)
     gV.pauseThread();

    //System.exit(0);

}


@Override
public boolean onKeyUp(int keyCode, KeyEvent event){
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        return true;


    }
    return super.onKeyUp(keyCode, event);
}}

Thank you, and I'm sorry if my english is so bad.

Dureo
  • 1
  • 1
  • 2
    in title you are saying onPuase is not called and in description you are saying is called. Please correct which ever is wrong – akkilis Jan 10 '13 at 12:54

1 Answers1

1
private boolean isActive = false;
@Override
public void onResume() {
   super.onResume();
   isActive = true;
}

@Override
pulic void onPause() {
  super.onPause();
  isActive = false;

}

//Do it if is not active
if(!isActive){
   //Operation you want to Perform
}

Try these.it might help you.

Nirav Tukadiya
  • 3,367
  • 1
  • 18
  • 36