It will be hack and a little unexpected behavior but.
When user switch the application the active application goes to background and new one is foregrounded.
Application.deactivate()
will be called when your app is scheduled to background. You could request going application to foreground again by 'UiApplication.requestForground()' and show the warning message.
Be careful because this logic should be quite sensitive in case of getting call or calendar event popup. You could imagine how user will be frustrated in this case.
I would have automatic logout after some duration of inactivity instead of your solution. And it would probably useful for people to have option for different intervals or even to switch off it.