Only calling the OnDestroy() of the mainActivity
<p>I am building an app that allows you to send files to other apps through a server. The thing is that when one of them closes the app by swiping it off, i want to send a disconnect message to the server.</p>

<p>The problem is that imagine that on the stack i have activities A (MainActivity) , B , C and D. If I am in the activity D and I swipe the app off (turn off the app), it will call the OnDestroy() method from the MainActivity. From the MainActivity, i can't send that disconnect message, so my question is <strong>why isn't the onDestroy() from the other activities called ?</strong> </p>

<p>PS: I could send the disconnect message from the MainActivity, but what if the person didn't reach the server part of the app? What if the person didn't try the part of the app that lets them send and receive files ? I would be sending a disconnect message for something that doesn't even exist.</p>

<p><strong>Or would there be any way where I could check, from within the MainActivity, if the activity D exists ?</strong></p>