用来记录一下方便自己查阅
@Override
protected void onStart() {
super.onStart();
if (!isCurrentRunningForeground) {
Log.d(TAG, ">>>>>>>>>>>>>>>>>>>切到前台 activity process");
refreshCurrentActivity();
}
}
@Override
protected void onStop() {
super.onStop();
isCurrentRunningForeground = isRunningForeground();
if (!isCurrentRunningForeground) {
Log.d(TAG, ">>>>>>>>>>>>>>>>>>>切到后台 activity process");
}
}
public boolean isRunningForeground() {
ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcessInfos = activityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo appProcessInfo : appProcessInfos) {
if (appProcessInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
if (appProcessInfo.processName.equals(this.getApplicationInfo().processName)) {
Log.d(TAG, "EntryActivity isRunningForeGround");
return true;
}
}
}
Log.d(TAG, "EntryActivity isRunningBackGround");
return false;
}