2016-11-19 4 views
0

私はアプリケーションを書いており、10秒ごとに情報をサーバーに送信したいと思います。まず、TimerとTimerTaskを使用していましたが、私がデバイスをスリープ状態にしたとき、私はうまく機能しませんでした。だから今、私はAlarmManagerを使用してみたいが、私はAlarmManager - 良いリピートを設定する方法

void startRepeatingSend() { 
    AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
    Intent intent = new Intent(context, MainReceiver.class); // odbiornik 
    intent.setAction("com.example.marcin.sbdintheroom.CYCLE"); 
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); 
    alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 5000, 5000, alarmIntent); 
} 

を繰り返し設定したいときに私は問題を抱えている私は、5秒にintervalMillisを設定するが、私の受信機はあなたができる分

答えて

0

ごとに1つだけの時間を放送受信しますThread.sleep(miliseconds)でアプリケーションを遅らせます。

try { 
    Thread.sleep(1000);     //1000 milliseconds is one second. 
} catch(InterruptedException ex) { 
    Thread.currentThread().interrupt(); // interupt thread when error 
    // handle error 
} 
関連する問題