I presume that you will use the RealtimeClockListener as a 'tick' that wakes up your application every minute. This works and is efficient, but does mean that your time out time will not be exactly 4 minutes - its actual duration will depend on whereabouts in the 'minute' the user becomes idle.
The trick is to determine what state your application is in when the tick happens or more accurately. I think the following sample code describes this, assuming that initially appInactiveTime is set to 0 and inForegrounFlag is true.
if ( Application.getApplication().isForeground() ) { appInactiveTime = DeviceInfo.getIdleTime(); inForegrounFlag = true; } else { if ( inForegrounFlag ) { // Was in foreground, start idle timing from now appInactiveTime = 0; } else { appInactiveTime = appInactiveTime + 60; } inForegrounFlag = false; }
I believe that using this code, appInactiveTime can now be used to find out if the app has been inactive for more than 4 minutes, by comparing it with 240 (60*4). .
At this point, your App should create and display a Global Screen, if you want it to show regardless of whether the app is in the Foreground or not. Then on the next tick, you can decide if you want to dismiss this screen or not, or if the user has dismissed it. I have the impression you need help with the timing rather than this part of the processing, so I will leave this with you.