Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2102] Android: Expose Keep Screen On

GitHub Issuen/a
TypeNew Feature
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2011-09-02T13:59:09.000+0000
Affected Version/sRelease 1.6.2
Fix Version/sSprint 2011-34, Release 1.8.0
ComponentsAndroid
Labelsmodule_window, parity, qe-testadded
ReporterDon Thorp
AssigneeDon Thorp
Created2011-04-15T03:10:31.000+0000
Updated2012-02-08T15:25:19.000+0000

Description

Expose ability to keep the display from going to sleep.

Comments

  1. Anthony Webb 2011-04-15

    +1 for this, would be a nice addition to 1.5.0

    I've got some "info at a glance" apps which all pretty much rely on being able to glance and get info without having to constantly wake the device. Thanks again for adding the ticket Don.

  2. Jeff English 2011-08-24

    setKeepScreenOn is the recommended method for GUI. WakeLock is needed for services. The following post is from an Android framework engineer: {quote} setKeepScreenOn() does prevent it from locking; it is just another way of setting the window flag to keep the screen on. PLEASE use these APIs instead of wake locks if keeping the screen on is associated with an activity or window. There are so many advantages: no need to get an additional permission, no chance you can accidentally cause the user's screen to stay on when they leave your app, no chance to have bugs like here where you crash, and just so much easier to do. Dianne Hackborn Android framework engineer hack...@android.com {quote}
  3. Don Thorp 2011-08-24

       var win = Ti.UI.createWindow({
       	backgroundColor : '#000033',
       	navBarHidden : true
       });
       
       var sw1 = Ti.UI.createSwitch({
       	width : "100dp",
       	height : "50dp",
       	bottom : "20dp",
       	left : "20dp",
       	value : false,
       	exitOnClose : true,
       	title: "View",
       	style : Ti.UI.Android.SWITCH_STYLE_CHECKBOX
       });
       
       sw1.addEventListener('click', function(e) {
       	if (e.source.value) {
       		sw1.keepScreenOn = true;
       	} else {
       		sw1.setKeepScreenOn(false);
       	}
       });
       
       var sw2 = Ti.UI.createSwitch({
       	width : "100dp",
       	height : "50dp",
       	bottom : "20dp",
       	right : "20dp",
       	value : false,
       	exitOnClose : true,
       	title: "Window",
       	style : Ti.UI.Android.SWITCH_STYLE_CHECKBOX
       });
       
       sw2.addEventListener('click', function(e) {
       	if (e.source.value) {
       		sw2.keepScreenOn = true;
       	} else {
       		sw2.setKeepScreenOn(false);
       	}
       });
       
       var b1 = Ti.UI.createButton({
       	title : 'HW Window w/ kSOn=True',
       	top : "20dp",
       	width : "auto"
       });
       
       b1.addEventListener('click', function() {
       	var w = Ti.UI.createWindow({
       		backgroundColor : 'green',
       		navBarHidden : false,
       		keepScreenOn : true,
       		title : "Created with keepScreenOn=true"
       	});
       	w.open();
       });
       
       var b2 = Ti.UI.createButton({
       	title : 'Window w/ kSOn=True',
       	top : "60dp",
       	width : "auto"
       });
       
       b2.addEventListener('click', function() {
       	var w = Ti.UI.createWindow({
       		backgroundColor : 'red',
       		keepScreenOn : true
       	});
       	var b = Ti.UI.createButton({
       		title : "Close"
       	});
       	b.addEventListener('click', function() {
       		w.close();
       	});
       	
       	w.add(b);
       	w.open();
       });
       	
       win.add(sw1);
       win.add(sw2);
       win.add(b1);
       win.add(b2);
       win.open();
       
  4. Michael Pettiford 2012-02-08

    Closing issue Tested with Ti Studio build 1.0.8.201201262211 Ti Mob SDK 1.9.0.v20120207171634 OSX Lion 10.7.3 Nexus S OS 2.3.6 Verified that I was able to keep the screen on using the sample code provided

JSON Source