Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does not Android retain application state after pressing Home button if application is ran first tyme from App Manager?

  • Steps to reproduce the problem.

    1. Create or dowload any application with several activities.
    2. Load apk file to sdcard or install from market.
    3. Install appliaction using standard App Manager.
    4. After installation in App Manager press Open or press on notification message after downloading.
    5. After application running go to the next (the second) application screen.
    6. Press HOME.
    7. Press application icon.
  • What happened.

Appliaction is restarting from the first screen and does not retain the second screen. Application retains activites in normal way after application restart or if you pressing BACK button in application to home screen.

  • Correct behavior should be.

Application must always retain activites in normal way.

How can I solve this problem for my application? Can I restart application during first run?

like image 823
degratnik Avatar asked Jul 08 '11 16:07

degratnik


1 Answers

Depending on how the application is defined in the manifest file and whether it has any mechanism to save and restore its state....

Based on your steps, it might create several instances of the same application (check this)

Or it is not using the instance Bunble in onCreate

It is definitely not going to be automatic for all applications to come back to the save screen it was at when it was paused or destroyed (some application do not want that, think about your bank account management...)

Edit :

So if I understand correctly from your comments, it works as you expect when you quit the application with the BACK key, but not when you use the HOME key...

Read the link I posted : http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html

You will understand that when you press the HOME key, the instance of your application you were in is not destroyed (and so the current state is not saved). Starting it again only starts another instance (from the initial screen).

When the user presses the BACK key, the current activity is destroyed and the previous activity resumes.

...

A task is a cohesive unit that can move to the "background" when users begin a new task or go to the Home screen, via the HOME key

If you want to change the way it behaves, look at the launchMode in the manifest.

like image 84
Matthieu Avatar answered Nov 04 '22 07:11

Matthieu