Reputation: 1966
In my application, I want to detect my application idle time(when user doesn't interact with the application for a number of seconds ) and lock app with Login activity, how could I achieve this?
I tried that was posted in this link:
but I am not getting idle time, the time starts at the time I launch my app
Please suggest what to do?
Upvotes: 2
Views: 1936
Reputation: 35661
It depends on your definition of "idle time".
I would consider idle time to when the app is not in the foreground therefore I would store the time that the app went into the background and then when it is brought back to the foreground compare the current time with the stored time to see if it should be locked or still open.
This method also has the advantage that no services or extra processes are required to count the idle time.
Upvotes: 0
Reputation: 445
I'm not familiar with android programming, but can't you adjust a timer that counts backwards and if a given variable(e.g. with value 5000) is 0 you do what you want to do.
If a user now interacts with your programm just set the value of the variable to 5000 again.
Upvotes: 2