Usually when if we minimize an app in a activity then it will be on the paused state so when we come back to the app it should start from the same activity that we leave before, So that the activity will onResume.
But my app(it is basicaly a simple puzzle game) does not act like this. If i minimize at any stage of my game and later if i come back to the game it starts totally a new game from the front page of my game. And most weird thing is that if i press back button that time it bring up the previously minimized activity to the front. I debug my code and found that there is a count down timer on my game this causes that problem. If i remove countdown it works perfectly that mean it start from the same activity i leave , never start new game if game is minimized.
In my game i have two activity , in 1st activity there is only one "START" button and 2nd activity has the countdown timer. So if i minimize in 2nd activity and re-open the app then totally new app will start while pressing back bring up prevoiusly open app which was minimized. 2nd activity code is :
public class GameCore extends ActionBarActivity {
// COUNTDOWN VARIABLE
CountDownTimer countdown_timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
if (countdown_timer != null)
countdown_timer.cancel();
start_countDown(120000);
}
private void start_countDown(long millisInFuture) {
// TODO Auto-generated method stub
countdown_timer = new CountDownTimer(millisInFuture, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
}
}.start();
}
}
I dont understand why count down timer force to open a new game if the game was minimized by the user. Can any one give me some direction of alternative way to do count down or have a solution for this. Thanks in advance.