How to know that last activity of certain type X is closed?
<p>I would like to run some action when all activities of certain type X are closed. The first idea is to have some global counter, that is decremented each time activity X is closed, and once the counter is 0, run some action. Assuming that process can be killed, the counter have to be persisted. But one more issue remains - imagine that activity X can crash (due to some bug in code), and in this case I'll not decrement the counter.</p>

<p>Any idea how to implement it in robust way?</p>
