Hey guys,
it is possible to create under Android a real time task?
I need a high performance timer which runs every 20 ms (without pause).
Background of my use case: I need a job for my audio play back handler
which puts received audio data to the audio buffer.
I used the 'ScheduledExecutorService' for this stuff.
It works, but only for the use, if my App is in foreground, if my App is in
background, it doesn't work (time increased from OS from 20 to 60 ms).
Here is my code:
@Override
public void run()
{
Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
ScheduledExecutorService playHandler = Executors.
newSingleThreadScheduledExecutor();
playHandler.scheduleAtFixedRate(myRunnable, 0, 20, TimeUnit.MILLISECONDS
);
}
Output (App in Foreground):
09-22 11:04:14.815: I/System.out(1176): xxx time: 20
09-22 11:04:14.835: I/System.out(1176): xxx time: 20
09-22 11:04:14.855: I/System.out(1176): xxx time: 20
09-22 11:04:14.875: I/System.out(1176): xxx time: 20
09-22 11:04:14.895: I/System.out(1176): xxx time: 20
09-22 11:04:14.916: I/System.out(1176): xxx time: 20
Output (App in Background)
09-22 11:04:21.677: I/System.out(1176): xxx time: 0
09-22 11:04:21.677: I/System.out(1176): xxx time: 0
09-22 11:04:21.735: I/System.out(1176): xxx time: 58
09-22 11:04:21.735: I/System.out(1176): xxx time: 0
09-22 11:04:21.735: I/System.out(1176): xxx time: 0
09-22 11:04:21.795: I/System.out(1176): xxx time: 60
09-22 11:04:21.795: I/System.out(1176): xxx time: 0
09-22 11:04:21.795: I/System.out(1176): xxx time: 0
09-22 11:04:21.853: I/System.out(1176): xxx time: 58
I've tested it also with a Timer and a manual builded endless loop and
Thread.sleep(),
but all of these tests doesn't work well for me.
Some ideas? Or is that not possible under Android?
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/841b0b03-ea98-4ab8-900d-6634b96ba325%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.