I am planning to implement a timer in my app such that only specific activities will have it, say I have 2 activities,1 fragment with this. When I move to activity 1, the timer starts and if I am still on the same view after 5 minutes, it should show an alert dialog asking to refresh the view. upon clicking ok it will refresh and restart the timer again(will start the countdown again) , upon clicking cancel, it will not refresh the page but restart the timer.
This should not happen if my activity or fragment is not in view. Say if I am on Activity 1, and the timer is at 2 mins, and I navigate to Activity 2, the timer goes to 0 and does not count in the background until the view is visible again.
Any ideas about whats the best approach to go about it? Any examples would help
Thanks in advance!