I’d like to know if my Activity was displayed because the user pressed back
on some other Activity. In the Lifecycle I couldn’t identify any Callbacks
that are robustly giving me that info.
onRestart() is not working. It will also fire if the Apps Task was brought to front.
onResume() will not work for the same reason.
I suppose there is a simple solution for that, but in Android supposedly simple things can be pretty nasty.
Call your 2nd activity with
startActivityForResult(Intent, int), then override theonBackPressed()in the 2nd activity and have itsetResult()toRESULT_CANCELED. Lastly, have the 1st activity catch that inonActivityResult().Code example:
Activity 1:
Activity 2: