相当于javax.swing.Timer中的机器人 [英] Equivalent to javax.swing.Timer in Android

查看:129
本文介绍了相当于javax.swing.Timer中的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些看起来像 javax.swing.Timer中的在Android上。我知道如何创建自己的主题,但有一些是像秋千计时器?

Is there something that looks like the javax.swing.Timer on Android. I know how to create own Threads, but is there something that is like the swing-timer?

推荐答案

也有Java的TimerTask的。下面是我的code,其中我在玩音频采样的例子:

There is also Java's TimerTask. Here's an example from my code where I'm playing audio samples:

import java.util.Timer;
import java.util.TimerTask;

// from constructor, shown here out of place
timer = new Timer();

// and in method, again, shown out of place:
        INTERVAL_MILLISECONDS = (int)((double)(bufSize) / (double)(nativeSampleRate * 2) * 1000);
        timer.scheduleAtFixedRate( new TimerTask() {
                public void run() {
                        synchronized(this){
                                track.write(data, 0, bufSize);
                                track.play();
                        }
                }
        }, 0, INTERVAL_MILLISECONDS);

这篇关于相当于javax.swing.Timer中的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆