Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 6:28 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Aug 04, 2011 3:04 pm 
Offline

Joined: Sun Jul 24, 2011 3:52 pm
Posts: 19
So, yesterday I spent 30 minutes trying to figure out a good way to stop my phone from going to sleep while my application is running so I thought I'd post it here.

In your main activity (the one that extends SlickActivity) add the following line to your onCreate method:

Code:
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);


Then, in your manifest file, right beneath your manifest definition, make sure you add the following line:
Code:
    <uses-permission android:name="android.permission.WAKE_LOCK" />


After you add that line, the beginning of your manifest file should look something like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.mangelok"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-permission android:name="android.permission.WAKE_LOCK" />


That's it! Now your app will automatically keep your phone screen on unless you push the power button causing it to go to sleep.

Hope this helps someone.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2011 6:21 pm 
Offline
Oldbie
User avatar

Joined: Thu Jan 13, 2011 4:42 pm
Posts: 349
Sweet! thanks for the tip.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group