0

In my project I need to distinguish between the app being in the background or the app was closed.

Example: I start up my app, and I log in, but I don't check the Stay logged in box. So If I close the App, It should log me out before it closes. (This is easily acquirable) BUT: The app can open google maps, and dial screen, which also puts the app in the background, so the Activity's onStop will be called too. And If I return from these screens to the App, I should remain logged in.

Kiskunk
  • 73
  • 11
  • You are starting Google Maps with an Intent so you know exactly that you did not close the app. Store a flag to represent that and check it in your `onStop` – Murat Karagöz Jan 05 '17 at 14:21

2 Answers2

0

You need to call it on the onDestroy, but if the user kills the app from the multitask menu, the onDestroy will not be called, so what I do. I scedule a task that needs to be executed in 10 minutes, if the user haven't come back to the app (I check this with a boolean in the sharedprefs, setting in onresume) I log the user out.

I figured it out with this -> Schedule task for a specific date & time in android

Community
  • 1
  • 1
vanlooverenkoen
  • 2,121
  • 26
  • 50
0

Overcame the problem by creating a boolean in MainActivity, and since it only has value when the Activity lives, it can be used when reopening the app or getting back to the app from background.

Kiskunk
  • 73
  • 11