Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, whenever you lock the screen (within a minute or two generally) the phone goes into sleep mode. You have three options that, two of which are better.</p> <ol> <li>Use <code>startForeground</code> on your service. That way, it will be in the front essentially. But it still would be affected by sleep mode.</li> <li>Use a <a href="http://developer.android.com/reference/android/os/PowerManager.html" rel="nofollow">WAKE_LOCK</a> - This is my favorite option, but it requires an extra permission in the app which ignorant users don't generally understand.</li> <li>Set an alarm with <a href="http://developer.android.com/reference/android/app/AlarmManager.html" rel="nofollow">Alarm Manager</a> - Since playing a notification takes about no proccessing time, this is probably the best way to do it, and then you would send a broadcast when the alarm triggers which would cause a <code>BroadcastReceiver</code> to make the notification sound. </li> </ol> <p>If you need a visual countdown timer, then also run the service, but don't rely on a service to stay awake without a WAKE_LOCK. Services also can be destroyed if the user has a bad phone or tries to use an app that uses way too much RAM - My phone would probably kill it because my phone sucks.</p> <p>I like wake locks, but Alarm Manager is probably the best way to do it.</p> <p>And the <code>Context</code> will stay the same regardless of the phone being awake or asleep. The context is based on the running process/class/block of code it's in. If the context were causing a problem, I would expect it to throw an exception and force close.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload