If I understand you correctly, your Activity A
would do something different if Activity B
doesn't get activated after A
was paused.
First of all, it's not a good idea to let an activity do something when it's not visible anymore. As we see in the Android lifecycle, it could get stopped:
I would put your background code into a service. This service gets notified whenever Activity A
or B
gets paused or resumed. There you could add a little timeout which has to pass till you start your logic.
If you do that, that would happen:
Case 1:
Activity A
goes into background and sends a message in the onPause handler to your service. Service starts its timeout timer. Activity B
gets started and sends a message in it's onResume handler to the service.
Now the services knows it's still the same activity and acts accordingly.
Case 2:
Activity A
goes into background and sends the message. The service starts its timeout timer. It timeouts (I think 200ms would be enough) and now your service knows the task isn't active anymore and acts accordingly.