Jump to content

  • Log In with Google      Sign In   
  • Create Account


Possible to prevent device to go to sleep?

  • You cannot reply to this topic
5 replies to this topic

#1 mileafly   Members   -  Reputation: 214

Like
0Likes
Like

Posted 24 August 2014 - 08:49 AM

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?



Sponsor:

#2 latch   Members   -  Reputation: 727

Like
0Likes
Like

Posted 24 August 2014 - 09:48 AM

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



#3 swiftcoder   Senior Moderators   -  Reputation: 9860

Like
0Likes
Like

Posted 24 August 2014 - 02:36 PM

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 - Software Engineer @Amazon - [swiftcoding]


#4 stupid_programmer   Members   -  Reputation: 1088

Like
1Likes
Like

Posted 24 August 2014 - 03:21 PM

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.



#5 C0lumbo   Crossbones+   -  Reputation: 2203

Like
0Likes
Like

Posted 24 August 2014 - 03:30 PM

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.



#6 Servant of the Lord   Crossbones+   -  Reputation: 18530

Like
1Likes
Like

Posted 24 August 2014 - 08:10 PM

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.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]






PARTNERS