Possible to prevent device to go to sleep?

Started by
4 comments, last by Servant of the Lord 9 years, 7 months ago

I am doing a concept for an "idle game" where the game is supposed to be playing itself apart from doing upgrades and stuff. This works well on desktop and browsers. But I think there will be a problem with mobiles that go to sleep if left alone. Is it possible to disable sleep mode somehow?

Advertisement

On android there is an intent you invoke to prevent sleep. I think it's called "prevent sleep."

I used it in this app:

https://play.google.com/store/apps/details?id=room.res

Feasibility aside, many mobile users will be very upset if you run their battery down to zero by inhibiting sleep...

What's to stop you designing the game in such a way that the simulation can progress even if the screen is off?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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.

On iOS, there's [[UIApplication sharedApplication].idleTimerDisabled = TRUE;

This is designed for preventing screen fade when watching FMVs, or if your input is purely tilting. It might be suitable for your case, but as others suggest, you shouldn't leave the sleep timer disabled for any longer than necessary.

Ultimately though, if your gameplay involves not touching the screen for long periods of time, then idleTimerDisabled is the right thing to use.

Could you design the game so that the game remembers the last time it was used (i.e. 9:09 PM 2014/8/24), and interpolates what "happened" the next time the user logs in? This would solve your problem (even when people shut down their desktops) and annoy users less. I wouldn't even want a browser page open continuously even on my desktop, unless it's something important.

This topic is closed to new replies.

Advertisement