Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In general, your code is not running if divice goes to sleep. In order to make your code running you need to acquire <a href="http://developer.android.com/reference/android/os/PowerManager.WakeLock.html" rel="nofollow">WakeLock</a> from <a href="http://developer.android.com/reference/android/os/PowerManager.html" rel="nofollow">PowerManager</a>. But in your case you don't need to have the WakeLock acquired all the time. You need to wake you application every 10 minutes. Otherwise your app will just eat battery doing nothing.</p> <p>In order to wake your application periodically you need to use a special Android's <a href="http://developer.android.com/reference/android/app/AlarmManager.html" rel="nofollow">AlarmManager</a>.</p> <p>Here is an example:</p> <pre><code>Intent myIntent = new Intent(getApplicationContext(), YourActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, myIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, interval, pendingIntent); </code></pre> <p>You also may send broadcast which you will process in your Service (if you don't want to use Activity). </p> <p><em>EDIT</em>: Playback will not start unless you explicitly create a SCREEN_DIM_WAKE_LOCK. Note that PARTIAL_WAKE_LOCK will not work with playback (don't now why, probably it's a bug).</p> <pre><code>PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Music"); wakeLock.acquire(); ...start playback... wakeLock.release(); </code></pre> <p><em>EDIT</em>: Added project that shows an example of running a playback every 60 seconds (even when screen is off and usb cable is disconnected). It can be found here: <a href="http://code.google.com/p/playevery60/" rel="nofollow">http://code.google.com/p/playevery60/</a></p>
 

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