Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
There is such a wonderful ActivityLifecycleCallbacks class. Here is a good example of usage: baroqueworksdev.blogspot.ru/2012/12/how-to-use-act...
The idea is this: in your class that implements ActivityLifecycleCallbacks, we start a counter that will count the number of started / stopped activities and the method a -for isAppInForeground().
private int startStatus = 0;
...
@Override
public void onActivityStarted(Activity activity) {
++startStatus;
}
@Override
public void onActivityStopped(Activity activity) {
--startStatus;
}
public boolean isAppInForeground() {
return startStatus > 0;
}
Only here is the trouble, onStop may not be called. The last method guaranteed to be called is onPause
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question