I'll start by saying that I've seen the Activity Lifecycle diagram (http://developer.android.com/reference/android/app/Activity.html) and actually I thouht that I understand it perfectly.
How I andestood it is that if there is an onDestroy event, then there is no coming back and the activity is definitely in a process of being shut down.
All the others that involve the ability to show the activity again are between onCreate and onStop (both inclusive).
I am creating an application that polls a custom bluetooth device for some measurements result. I want the connection (Bluetooth) to be kept, but I also want to discover if the user kills the activity (from the taskbar by killing the application) so I can send one more thing to the device and disconnect the socket. So by what I understood, I can just put the code in onDestroy. It turned out however (Sony Xperia Z3 and Samsung Galaxy S2) that onDestroy is also being executed when the user clicks the power button, thus locking the screen. When the screen is unlocked, a new Activity (that is my guess) is created and onCreate is run. And as You can guess - my device is disconnected because of the code i put to onDestroy
Normal automatic screen off + lock does not do onDestroy...
So the point is: Is there a way to distinguish the onDestroy that really destroys the activity, and the onDestroy that will recreate the same activity afterwards when the user unlocks the screen? I want just to react to this really-really onDestroy event
Yes there is a way to distinguish onDestroy that destroys your activity: