Timer to Return to Main Activity

Bill Norris

Active Member
Licensed User
Longtime User
Have several activities in my app. I would like to automatically return to main after a period of inactivity throughout the app. Am not sure what approach to take. Perhaps a global variable that resets to 0 every time any activity or view is touched/clicked, etc, then a timer that ticks occasionally to increment the value of the variable, then starts the main activity when it reaches a certain value?? Can you run a timer as a service? Also, is there a way detect touching/clicking throughout the app without having to add code to each every sub?
 

lagore

Active Member
Licensed User
Longtime User
I would not use a timer as it will not be updated when your app is paused, the easiest thing is to use a global 'long' which is set to the current time on startup then for timeout just compare it to (current time - the allowed time) on resume in which ever activity if yes keep running this activity and reset the 'long' if no then start 'Main'
 
Upvote 0
Top