Context
I'm one of the developers working on a pretty large and very complicated project. Half of the project is written with JavaScript and the other half with Java, moreover about 30% of the base product comes to us pre-compiled, so we cannot exactly look inside or debug through it.
Problem
When our application comes back to foreground the activities stack gets destroyed and only the root activity is displayed. I cannot track down why.
Things I've tried so far
Question
Are there any strategies to find what caused a certain lifecycle method to be called?
Update 1
Thank you for the great questions and the help in the comments section. Here is the sequence diagram to explain better what is happening.
Update 2
Here are the screenshots of the memory usage
When I launch the application
When I launch Activity B
When I send the application to the background
When I return to foreground
Using activity. isFinishing() is the right one solution. it return true if activity is finished so before creating dialog check for the condition.
An activity provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app.
And the solution is found!
Turns out that my root activity had the following property set:
android:clearTaskOnLaunch="true"
Here is a quote from the documentation:
android:clearTaskOnLaunch Whether or not all activities will be removed from the task, except for the root activity, whenever it is re-launched from the home screen — "true" if the task is always stripped down to its root activity, and "false" if not. The default value is "false". This attribute is meaningful only for activities that start a new task (the root activity); it's ignored for all other activities in the task. When the value is "true", every time users start the task again, they are brought to its root activity regardless of what they were last doing in the task and regardless of whether they used the Back or Home button to leave it. When the value is "false", the task may be cleared of activities in some situations (see the alwaysRetainTaskState attribute), but not always.
Suppose, for example, that someone launches activity P from the home screen, and from there goes to activity Q. The user next presses Home, and then returns to activity P. Normally, the user would see activity Q, since that is what they were last doing in P's task. However, if P set this flag to "true", all of the activities on top of it (Q in this case) were removed when the user pressed Home and the task went to the background. So the user sees only P when returning to the task.
If this attribute and allowTaskReparenting are both "true", any activities that can be re-parented are moved to the task they share an affinity with; the remaining activities are then dropped, as described above.
And here is a great article which helped me to find it: http://developer.android.com/guide/components/tasks-and-back-stack.html
Not sure if this will work:
@Override
public void finish() {
super.finish();
Log.d("derp", "who is calling me?", new RuntimeException());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With