How to find out if device is in sleep mode?

by JP » Tue, 26 May 2009 14:13:56 GMT


Sponsored Links
 I am sure it is buried in the SDK somewhere... but I couldn't find it.
This is relevant to a service running in the background: How can I
find out if the device is in sleep mode?

--~--~---------~--~----~------------~-------~--~----~



How to find out if device is in sleep mode?

by Mark Murphy » Tue, 26 May 2009 18:07:21 GMT


 


If your code is in position to ask the question, you're not in sleep
mode... ;-)

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Warescription: Three Android Books, Plus Updates, $35/Year

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


How to find out if device is in sleep mode?

by JP » Tue, 26 May 2009 21:30:57 GMT


 Well nomenclature...

Here's the scenario: I've got an app that implements the relevant data
processing and backend server connectivity through a Service that I
keep running on a reduced ("sleep") activity level when the user puts
the device to sleep (using end button) or when the screen timeout
hits. I can follow this status change, because it triggers calls to
overloaded onStop() and onPause() methods of the app's subclassed
Activity. This way, I control active/reduced ("sleep") activity levels
of that Service. Everything's cool and dandy in this scenario.

Enter an AppWidget that's using this Service in a similar fashion,
with functionality implemented in a subclass of AppWidgetProvider.

This changes the game - I have found no way to determine when to set
the Service to the reduced ("sleep") activity level from that point.
The app's Activity has long paused, and I keep the Service at active
level, as the widget needs updates from the Service similar to what
the Activity needs when in front. With the AppWidget on the home
screen, I want, and should (re: battery life), drop the Service's
activity level when the device enters sleep mode. The most elegant way
to handle this would be to detect whether the device sleeps (or, on
second thought, better actually, whether the display is dark) right
inside the Service. This way, as a side product, I can also drop
following the device status in the overloaded onStop(), onPause(),
onStart() and onResume() methods.









--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. which is better to use to avoid mem leaks==> getbasecontext or getApplicationcontext

public 
Context<http://developer.android.com/reference/android/content/Context.html>
getApplicationContext ()
Since: API Level
1<http://developer.android.com/guide/appendix/api-levels.html#level1>

Return the context of the single, global Application object of the current
process.


 public 
Context<http://developer.android.com/reference/android/content/Context.html>
getBaseContext ()
Since: API Level
1<http://developer.android.com/guide/appendix/api-levels.html#level1>
 Returns

   - the base context as set by the constructor or setBaseContext

Since applicationcontext is global application object,

To avoid objects retained in memory after activity is closed (assuming this
application has lots of activities), its better to use getbasecontext
Is my understanding right.?

Thanks for all your inputs.

-- 

2. How to disable home and other buttons so as to persist an app?

Hi,

Thanks Mr Romain Guy, for the information.

@Mike dg : The requirement is that one app has to be loaded at startup which
displays a browser with a specified URL. And one of the requirement is that
whatever buttons the user presses or clicks, the browser shouldn't exit. The
browser with the specified URL should be the only app that the user has
access to.

Since the 'Home' button on being pressed, exists the application, the above
requirement can't be implemented.






Ashok Jeevan
+91 9895401278







> > 

3. Multi Touch - Does anyone know how it works

4. Flash to JC4

5. Dibutuhkan Blackberry, Brew, Android, Iphone dan/atau J2ME Developer

6. Flash on Nexus kereeennn

7. japri : wta blitz Yahoo Messenger :-)