当所有Activity都执行过stop可以理解为进入后台
在Application类里执行注册:
registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle bundle) {
}
@Override
public void onActivityStarted(Activity activity) {
//从后台回到了前台
mActivityActiveCount++;
}
@Override
public void onActivityResumed(Activity activity) {
}
@Override
public void onActivityPaused(Activity activity) {
// 不在pause上做,因为可能只是被简单的第三方遮住
}
@Override
public void onActivityStopped(Activity activity) {
mActivityActiveCount--;
//从前台回到了后台
if (mActivityActiveCount == 0 ) {
ToastTools.showShort(getApplicationContext(), "XXX进入后台运行");
}
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
});
网友评论