-3

I'm developing an application right now, the problem is that when I pressed home or open whatsapp from notification and reopen the application, it restarted from the beginning of the application, instead of resuming to the state it was left.

While locking and then unlocking the screen resumes to the state where it was left.

So, I tried tracing the life-cycle between those two process (locking screen & opening other app/home). What makes me confuse is that both process show same lifecycle , onPause() and onStop() are triggered when I locked the screen or open other app/home. Then, when I returned to the app, onRestart() and onResume() are triggered.

If both shows the same result, why locking the screen and unlocking continued the application, while pressing home or another application and reopen application did not?

Any solution or explanation is appreciated. Thanks.

Code :

@Override
protected void onRestart(){
    System.out.println("Restart");
    super.onRestart();
}

@Override
protected void onResume(){System.out.println("Resume");
    gamePanel.resumeActivity();
    super.onResume();
}

@Override
protected void onPause(){
    gamePanel.pauseMusic();
    gamePanel.pauseActivity();
    System.out.println("PAUSE");
    super.onPause();
}
@Override
protected void onStop(){
    System.out.println("STOP");
    super.onStop();
}
@Override
protected void onDestroy(){
    content.removeView(gamePanel);
    content.removeView(editText);
    gamePanel.stopMusic();
    System.out.println("DESTROY");
    super.onDestroy();
}
Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
user3411184
  • 71
  • 1
  • 10
  • 1
    this question is somewhat too broad for this website. In general, from point of view of Activity lifecycle those two situations are equivalent. the only difference is when you start another application you create additional process that consumes system resources, and at certain point system can decide to kill some old processes. And before asking such questions I would still recommend to read the [documantation](http://developer.android.com/training/basics/activity-lifecycle/index.html) – Chaosit Aug 03 '15 at 08:57

1 Answers1

0

I think you have to use onSaveInstanceState(Bundle savedInstanceState) for that to achieve your data at the time your app destroyed. Please take look of that Link, it will help you.

Community
  • 1
  • 1
ULHAS PATIL
  • 862
  • 8
  • 19