How to detect when device has resumed from sleep mode - android

Is there a way to detect when the android system has resumed from sleep mode, but has not turned on the screen? My service does not need to acquire any wake locks, but does need to know when the device has been woken up by another process.

Related

Does a foreground service need a wake lockt to stay active after screen-off?

In different sources, I read that a foreground service requires a wake lock to stay active after the device goes to sleep. But when I test it by starting a foreground service and turning the screen off while the device is unplugged (both on emulator and on a real Samsung device), the foreground service keeps running.
Does a foreground service require a (partial) wake lock to stay active after the screen is off?
From my experience of developing a timer, the answer is yes, especially when the screen is off.
Without a wake lock, the foreground service will be killed or suspended in a few minutes(2 ~ 10m in my tests). Sometimes, when the screen is off, the code won't be executed but the foreground notification still exists and the code only starts being executed after the screen is turned on. This makes debug very hard. This situation is more common if the test device is from Chinese manufacturers(Foreground service + Wake Lock + Letting user whitelist your app seems the only solid option if your app targets Chinese market).
Use a wake lock if you want your service keep running after the screen is off.

Android: Does CountDownTimer still work after the phone gone to sleep

Will the CountDownTimer work when the phone gone to sleep mode? If it doesn't, is there a broadcast receiver which I can detect whether the phone gone to sleep and awake again?

Doze mode and App Standby

How can I know in my app if the phone is in Doze mode or if my app is in Standby mode?
Can I also know it by using some subscribing approach?
There's a difference between App Standby (where your app goes to
sleep because it's lonely) and Doze (where the system went to
sleep because users have lives).
Doze only works when your device remains stationary. If you pick it up or wake the screen, Doze mode is deactivated and the timer
resets. It won’t ever turn on when the phone is sitting in your pocket
unless you’re sitting remarkably still. Doze simply keeps your phone
from burning through the battery while it’s asleep on a desk or table
or something.
An app that goes into Standby loses all network access and all its
background sync jobs are suspended. These restrictions are temporarily
lifted when your phone is plugged in and for a few minutes every day
or two. This gives suspended apps a chance to run any pending sync
jobs, but they won’t be allowed to continue running. A high-priority
push notification will also be able to wake an app from Standby for a
short time.
Note: Google has also noted that it isn’t acceptable for apps to
fire off notifications simply to remain exempt from App Standby. This
sort of behavior can get an app banned from the Play Store.
For more details with testing Doze and App Standby, Please visit this link: https://developer.android.com/training/monitoring-device-state/doze-standby.html
Thanks!
You don't need to do anything to manage Standby mode. You just need to manage you lifecycle as usual. There will be a time in the day when you app is gonna be resumed (so you can sync data and resume delayed jobs), but notifications and alarms will always bring your app out of standby.
Check this out: https://plus.google.com/+AndroidDevelopers/posts/76eh5MaJaXj?linkId=18331776

Android service continues running even when phone is sleeping

From everything I read, by default, a Service should stop running after the phone is in sleep mode. This is what I want, but for some reason, the Service is continuing to run when the phone is sleeping. I am starting it with the startService in my app's only activity. How can I make my service stop when my phone is sleeping and then start back up when the phone is turned back on?

Track restarts, shuts down, power up and power down

can we get notification if user restarts, shuts down, power up or down the device
Ajay,
The two Broadcast Actions you are most likely interested in are:
ACTION_BOOT_COMPLETED: This is broadcast once, after the system has finished booting.
ACTION_SHUTDOWN: Device is shutting down. This is broadcast when the device is being shut down (completely turned off, not sleeping).
Please keep in mind to receive ACTION_BOOT_COMPLETE you must have the RECEIVE_BOOT_COMPLETED permission in your AndroidManifest.xml

Categories

Resources