Android Timer which works on both background and foreground -


i'm working on app track students' studying time. student can press start button , start studying. , stop when finish studying.

when screen on or phone plugged in,the text view , progress bar updating every second .(i means works fine) when screen off,updating textview , progress stopped after 10 seconds of sleeping phone. think may activity pausing. right?

i tested using:

  1. partial wakelock
  2. service

both of these ways make battery drains. there idea case? thanks.

you should use service class, work in background when activity puased

enter link description here enter link description here