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.