Volver a las tareas desde Inicio

Lo que tengo:

I have 3 activities in my app with a basic nested structure:

Activity 1 --> Activity 2 --> Activity 3

Activity 2 contains data embedded in an ArrayList<CustomClass>. CustomClass extends application (as taught aquí) and Activity 3 uses this to modify the CustomClass data for Activity 2.

Lo que yo quiero:

When the user hits the Home button and then opens my App again later, I want to return to whichever activity was on the top of my stack. (I thought this is supposed to be Android default behaviour.)

It works fine on my Eclipse emulator but on both my Google Nexus One and Huawei Honour, the task is completely restarted.

I have tried setting my activities to run in standard, singleTop and singleTask launch modes. The best result I could get on the phones was to return to Activity 1 (which is just a form) and still display what I had entered into the text fields before creating Activity 2.

I did also notice that if I hit Home then check the Running Applications under Settings, my app is not listed. Maybe Android might be destroying my task and I need to save the activity state. But this doesn't make sense if I press home and immediately re-enter the app?

Se agradece el consejo.

preguntado el 30 de junio de 12 a las 22:06

1 Respuestas

There is no guarantee that once you hit the Home button and your Activity goes in onPause() it will keep its state (even it it keeps the same state, there is no guarantee on the actual amount of time the activity will remain in memory). This depends on the device in particular and how it handles its internal memory. (see esta figura which shows the Android Activity Lifecycle).

The best practice is to always save your state in the onSaveInstanceState método. Esta entrada provides a good and easy example on how to do that.

contestado el 23 de mayo de 17 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.