我希望这里显示的代码一直运行:
class secondClass extends TimerTask {
MediaPlayer mp;
public void onCreate(Context context) {
mp = MediaPlayer.create(context, R.raw.flyinghome);
}
public void run() {
float x = (float) Math.random();
float y = (float) Math.random();
mp.setVolume(x, y);
}
public static void main(String[] args) {
secondClass task = new secondClass();
Timer timer = new Timer();
timer.scheduleAtFixedRate(task, 0, 2000);
}
}如果TimerTask类扩展了活动并实现了OnCLickListener,那么如何让这个MainActivity类与MainActivity类同时运行。
发布于 2014-01-30 18:26:33
您也可以考虑使用Android服务。
https://developer.android.com/reference/android/app/Service.html
https://stackoverflow.com/questions/21445941
复制相似问题