Android : How to alert a stopped activity when it is no longer in the active task stack?

on Friday, April 17, 2015


Motivation: I want to do some operation foo() when I leave a certain activity A. However, I am having trouble defining leave. In particular



  • Leaving Activity A means I enter the home screen, or return to the main activity that launched it


however




  • Activity A can open activity B, activity C, etc., each of which may open its own activity. When we leave any of these activities, we've left Activity A.




  • Each activity B, C, etc. can access return to mainactivity or home in its own way. There are many of them, but I don't want to make changes to them individually or the base activity class if possible.




  • I only care about when Activity A has left - this isn't a recursive thing, though it sounds like it.




Originally I had some code in the lifecycle functions and the onHomePressed/onBackPressed buttons, but I realize those weren't enough to tell if I've left. It could be that I've stopped and another activity is in foreground and the user leaves from that app.


The only pattern I can find is that I've left when my activity A is no longer in the active task stack. Hence my question;


Is there someway to alert my stopped Activity A when it is no longer in the active task stack?


0 comments:

Post a Comment