I have an Activity that starts an AsyncTask. The activity is allowed to show in Portrait or Landscape orientation. When the orientation is changed, the Activity is destroyed and recreated. The task continues working no matter how many times the orientation is changed. It also returns the results to the activity successfully (according to CommonsWare's answer here http://goo.gl/WF1yW).
What I want to achieve is: when the activity is destroyed because the application is closing - the task should be cancelled. However, when the activity is destroyed because of an orientation change - the task should NOT be cancelled.
Basically the question is how to distinguish between the two cases: application is closing / orientation change. In both cases the onDestroy() method is called and there is no easy way to check something like isChangingOrientation()...
P.S. I can also consider a totally different approach if necessary.