Handling back button depending on display state