Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

java - Auto logout after X minutes, Android

I'm looking to implement a feature that logs out the user after X minutes of inactivity. After going through a similar answer on SO, the suggested method seems to be to -

  • Have a timer running in the background. Schedule it to timeout after x minutes.
  • In every function where the user interacts with the app (basically all event handlers), call a method that resets the timer.

I can't think of anything better than this myself, but it's seems to be a huge pain even for a medium sized application that has 6-7 different screens and a whole bunch of UI components. Is there a better way to handle this?

Thanks,
Teja.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use a CountDownTimer and restart it from onUserInteraction() in every Activity()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...