Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class MyRunnable implements Runnable {
  2. List<Long> times = new LinkedList<>();
  3. int cnt, maxCnt;
  4. long delay;
  5. long firstTime;
  6. Handler h;
  7.  
  8. public MyRunnable(Handler h, int maxCnt, long delay) {
  9. this.h = h;
  10. this.maxCnt = maxCnt;
  11. this.delay = delay;
  12. }
  13.  
  14. @Override
  15. public void run() {
  16. if (firstTime == 0) {
  17. firstTime = SystemClock.uptimeMillis();
  18. }
  19. times.add(SystemClock.uptimeMillis() - firstTime);
  20. if (cnt++ < maxCnt) {
  21. h.postAtTime(this, firstTime + cnt * delay);
  22. } else {
  23. Log.d(TAG, "delay: " + delay + ", times: " + times);
  24. }
  25. }
  26. }
  27.  
  28. // code:
  29. Handler h = new Handler();
  30. h.post(new MyRunnable(h, 60, 100));
  31. h.post(new MyRunnable(h, 5, 1000));
  32. h.post(new MyRunnable(h, 2, 2000));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement