How to get Apps Inactivity postion?

Hell Sir,
I want to log out after certain time of app inactivity. Is there any function so that i can use?

Please help me…