Issue
I have a stock Nexus 5 running 4.4.2 (using ART if it matters) and I've found an interesting scenario. I have this as my onDestroy()
:
@Override
protected void onDestroy() {
super.onDestroy();
t.setText("onDestroy");
t.show();
}
It's a GPS oriented app so I'm up and walking around. I am using the technique mentioned in this question to show a lot of debug toast messages.
Anyway, when I rotate my app, the toast appears. I understand that the activity is destroyed and recreated for the new orientation, but how can I know what's really going on? How can I tell when my app is REALLY getting destroyed and not just being rotated? Similar to this question, I want to log out when a particular activity is destroyed.
Solution
Since Honeycomb, the isChangingConfigurations()
method can be queried to check whether the Activity
is being recreated due to configuration changes. Alternatively, the isFinishing()
method can be queried on any API level to check whether the Activity
is actually being finished, or is only being destroyed temporarily by the system.
As far as I can determine, the two methods should always return mutually consistent results in practice. The only point where they might have diverged is when the system kills the process to clear memory, but there are no callbacks or interaction with the app at that point.
The documentation of the onDestroy()
method mentions the use of the isFinishing()
method:
Perform any final cleanup before an activity is destroyed. This can happen either because the activity is finishing (someone called
finish()
on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with theisFinishing()
method.
Answered By - corsair992
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.