Added functions for when app is brought into the foreground and leaves foreground.