I found at Tracking user idle time within the app in Android an answer which I tried to use, but it does not work for me.
I tried to use the above mentioned code but I get NullPointerException because sPreferences is null in getElapsedTime(). Any idea how to fix this? Hopefully somebody would be kind enough to help.