How do you detect when an Android app goes to the background and come back to the foreground?

How do you detect when an Android app goes to the background and come back to the foreground?
Answer
Using the following code you can detect if the App comes foreground. This is how to detect if the App goes background.

…

The callback sequqnce will be,
  1. onPause()
  2. onStop() (–activityReferences == 0) (App enters Background??)
  3. onDestroy()
  4. onCreate()
  5. onStart() (++activityReferences == 1) (App enters Foreground??)
  6. onResume()
 

Tìm kiếm

Back
Top