Yes. However for a more robust solution you need to think of the expected case where the app is not always in the foreground.
It might be better to use a timer with 10 seconds interval that is only enabled when the activity is in the foreground and saves the number of ticks to a file each tick event.