0

I am a beginner with Android, developing my final project for University. I have a problem that I do not know how to solve or how to start with it. When I launch my app I interact with it and then i press Home button on the emulator. I do whatever else and then I press the button to see open apps and select my app and then it opens in the very exact situation it was when i left it to go to the home... That's what I wanted BUT if while running my app I change to another app or go to home and I launch the app from the menu (press menu and find my app in the grid and tap the icon) it launches the app from the launch activity, being a new instance, overriding the previos app status...

What can be the error? What info should I provide to get some guidance?

Thank you very much in advance and excuse my messy explanation... Miguel

PD: I tried to find this same issue, but I found nothing because I do not even know what to google for.... sorry

mamoreno
  • 3
  • 4
  • http://developer.android.com/guide/topics/resources/runtime-changes.html is one place to start. also look at http://developer.android.com/training/basics/activity-lifecycle/index.html – techi.services Jul 09 '13 at 22:06

3 Answers3

1

Perhaps, you should understand the Android Activity life cycle first. http://developer.android.com/images/activity_lifecycle.png

Then you have to override all these methods (given in the diagrom) and you should use the debugger to know how, when, which method is called and note down the activity state in every case. The methods are:

@Override
protected void onPause() {
    super.onPause();
}

@Override
protected void onResume() {
    super.onResume();
}

@Override
protected void onRestart() {
    super.onRestart();
}

@Override
protected void onStart() {
    super.onStart();
}

@Override
protected void onStop() {
    super.onStop();
}

@Override
protected void onDestroy() {
    super.onDestroy();
}

Then to override them, you can add your own code to maintain/save the activity sate.

Husnain Iqbal
  • 466
  • 6
  • 16
  • You can get brief details about android activity life cycle on here. http://developer.android.com/reference/android/app/Activity.html – Husnain Iqbal Jul 09 '13 at 22:12
  • I will try this... I thought it was something like this, since I have everything about initialization on the onCreate... but why does it work in the first scenario? is it because the app wasn't destroyed yet? Thank you :) – mamoreno Jul 10 '13 at 06:20
0

Save the state of your application inside the onPause() of the Activity. Place your code to restore the state of your application inside of onResume() inside of the Activity. This is part of the Activity lifecycle.

Just don't let the onResume() misleading language confuse you. The thing that resumes is the UI thread in this case, so this method will get called even when the application initially begins (when the UI appears).

If you have trouble fixing this, just post your Activity code in your question.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
0

The developer guide has a good introduction on this topic:

http://developer.android.com/training/basics/activity-lifecycle/recreating.html

Kai Stavginski
  • 549
  • 4
  • 9