If you want the 20-second counter to be restarted at each screen change, then do the activities extend an Activitycase, in whose onCreate() method the 20-second counter thread is started (only if savedInstanceState == null, of course, to avoid restarting the counter in case of screen rotation). Hit the 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 change screen only 10 seconds to appear Alertdialog, do so: Activityto register a broadcast receiver in onResume() and "unregister" in onPause(). Start a thread counter in a separate class and, when the counter is over, launch a broadcast, which the currently foreground activity will be ready to receive.