If you want the 20-second counter to be restarted with each screen change, then do the activities extend a Base Activity, whose onCreate () method starts the 20-second counter thread (only if savedInstanceState == null, of course, to avoid resetting the counter in case of screen rotation). At the end of 20 seconds, he calls AlertDialog through a Handler.
However, if you want the counter to be global for the application, so that the user stays 10 seconds on a screen and when switching screens are only 10 seconds away to appear AlertDialog, do as follows: ActivityBase should register a broadcast receiver in onResume () and "unregister" it onPause (). Start a counter thread in a separate class, and when the counter runs out, launch a broadcast, which the activity currently in the foreground is ready to receive.