-2

I have a requirement of Logging out the user from the app when he goes to background and make a service call indicating logout is done. Also the same has to be done if user is inactive for a few minutes.

Can some one help me in this regard. A sample would be more helpful.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Raviteja
  • 97
  • 3
  • 16
  • 1
    Did you try anything so far? – Rohit5k2 Jun 05 '18 at 06:54
  • For background call service in "onPause()" method and do what you want – Shiv Kumar Jun 05 '18 at 06:58
  • https://stackoverflow.com/questions/4414171/how-to-detect-when-an-android-app-goes-to-the-background-and-come-back-to-the-fo – jakir hussain Jun 05 '18 at 06:59
  • check this -http://steveliles.github.io/is_my_android_app_currently_foreground_or_background.html – Adil Jun 05 '18 at 07:25
  • @Rohit5k2 yes, I tried with `LifecycleObserver` to a class that Extends Application class. I am able to get the app state of ForeGround and Background. I tried to start a Service from this Application class when Background event is fired but Service `OnstartCommand()` throwing null pointer exception. Hence i posted this question. – Raviteja Jun 05 '18 at 11:23

1 Answers1

0

Here you can use onPaused method when ever on paused method you can store current time of that and when you come back again at that time you calculate at current time and get different and you can set any of that diffrent and it is more than that you can log out their.

Mehul Tank
  • 195
  • 15