Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyRunnable implements Runnable {
- List<Long> times = new LinkedList<>();
- int cnt, maxCnt;
- long delay;
- long firstTime;
- Handler h;
- public MyRunnable(Handler h, int maxCnt, long delay) {
- this.h = h;
- this.maxCnt = maxCnt;
- this.delay = delay;
- }
- @Override
- public void run() {
- if (firstTime == 0) {
- firstTime = SystemClock.uptimeMillis();
- }
- times.add(SystemClock.uptimeMillis() - firstTime);
- if (cnt++ < maxCnt) {
- h.postAtTime(this, firstTime + cnt * delay);
- } else {
- Log.d(TAG, "delay: " + delay + ", times: " + times);
- }
- }
- }
- // code:
- Handler h = new Handler();
- h.post(new MyRunnable(h, 60, 100));
- h.post(new MyRunnable(h, 5, 1000));
- h.post(new MyRunnable(h, 2, 2000));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement