私はこの小さなコードを作成しました:
public class Game1Activity extends Activity {
/** Called when the activity is first created. */
private final Handler handler = new Handler();
private final Runnable run = new Runnable()
{
public void run(){
update();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
update();
}
public void update(){
try
{
Log.i("update thread", "updated");
}
catch (Exception e)
{
Log.i("update thread", "catched an exception!");
}
finally
{
handler.postDelayed(run, 33);
}
}
}
ご覧のとおり、 33 ミリ秒 (30 fps) ごとに更新されたログ チャットに書き込むこと以外に特別なことはありません。
ログチャットからわかる場合、ここに私の問題があります:
09-15 09:01:05.955: I/update thread(423): updated
09-15 09:01:06.025: I/update thread(423): updated
09-15 09:01:06.097: I/update thread(423): updated
09-15 09:01:06.166: I/update thread(423): updated
09-15 09:01:06.236: I/update thread(423): updated
09-15 09:01:06.305: I/update thread(423): updated
09-15 09:01:06.374: I/update thread(423): updated
09-15 09:01:06.444: I/update thread(423): updated
09-15 09:01:06.513: I/update thread(423): updated
スレッドは約 70 ミリ秒ごとに実行され、意図した時間の 2 倍になります。なぜそれが起こるのですか?私のスレッドは最も基本的でシンプルです。それを遅らせることができるものがあるかどうかは疑問です
意図したとおりに更新するためのより良い方法はありますか?