Don't prevent the app from going to sleep. Horrible thing to do. iOS/Android will let you know when the app is going to be deactivated and then brought back to the front. Save your state when the game is going away and then calculate the difference when it comes back.
For iOS the UIApplicationDelegate has 'applicationDidEnterBackground' and 'applicationWillEnterForeground' (also applicationWillResignActive/applicationDidBecomeActive). And for Android the Activity has 'onStop' and 'onResume'. Any decent third party engine will bubble those events up to the client code in some form.