I have an app which track user activity on app which include time etc, Now if user has opened the app, It will start an session and till user in this app , his session will cont
Extend all your Activities from BaseActivity like below. This is the best option for you as onPause and onResume methods are guaranteed to be called whenever your Activities show up or go away from phone screen.
class BaseActivity extends Activity {
@Override
protected void onResume() {
super.onResume();
// Start Logging
}
@Override
protected void onPause() {
super.onPause();
// End Logging
}
}