Activityが最上位にあるかどうかを判断
1201 ワード
PhoneWindowManager.java , Activity。 。
: ,
public boolean isActivityTop(Sting packageName){
ActivityManager am = (ActivityManager) mContext
.getSystemService(Context.ACTIVITY_SERVICE);
if (am != null) {
ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
if (cn != null && cn.getPackageName() != null) {
if(packageName.equals(cn.getPackageName())){
return true;
};
}
}
return false;
}
:
private boolean isTopWindowActivity(WindowState win,String activityname){
if (activityname == null) return false;
final WindowState curWin = mFocusedWindow != null ? mFocusedWindow
: mTopFullscreenOpaqueWindowState;
WindowState windowState = null;
if (win != null && win.getAttrs() != null) {
windowState = win;
} else if (curWin != null && curWin.getAttrs() != null) {
windowState = curWin;
}
if (windowState.toString().indexOf(activityname) != -1){
return true;
}
return false;
}