Android: How to know if an activity is finished?

if you are using Kotlin use this

override fun onStop () {
    super.onStop()
    //do stuff
}

Here is more on the topic


Try triggering those in the Activity lifecycle methods onStop or onDestroy. Check this documentation for more details.

onStop will be triggered when user clicks on back button. So handle your events in onStop.

@Override
public void onStop () {
    // Do your stuff here
    super.onStop() 
}

Eventually, onDestroy will also be called, but not necessarily as soon as the back button is clicked.