How can I detect closing of an application?

Yes I am having the same problem till now. Almost a year now!