views:

44

answers:

1

Hello, I'm wondering what is the highest level I can go in-order to know when the user interacts with my application

preface: I'd like to logout of my application after X seconds of user inactivity. so what I did is create a service with a timer, and a toggle function which resets the timer to X time. after X time has passed, an intent is raised, and a broadcast receiver catches that intent and preforms the logout (closing the open logged in activities as well...)

as for the actual question, I need to call the "Timer Toggle" function each time the user interacts with the application. where is the highest place in the android app that I can know when the user interacts with the phone

The only thing I found is to implement onClick and onKeyPress for each activity, is there another better way? maybe in the Application class?

+1  A: 

I don't think there's any other way aside from sending events from the Activity itself.
You could look at overriding Activity.onUserInteraction().

But is it likely that the user will be in a single Activity of your application for "X seconds" without ever switching screens, or letting the device go into sleep?

I imagine it would be sufficient to update the timer/flag in onCreate, onPause and onResume. Plus maybe some commonly-called functions within the Activity.

Christopher
Well, it might happen because its a content app, so for example, the user might be reading something. but Ill think about maybe doing it your way.
omri
but Ill think about maybe doing it your way.
omri