1

我在一个 AppLocker 应用程序上工作,我使用下面的函数来检查顶部 Activity 的变化但是有没有比使用“while(true)”检查每秒更好的方法呢?

   while (true) {
        String s = getlauncherTopActivity();
        if (utils.islock(s)) {

            if (!s.equals(kes)) {
                if (!s.equals(currentHomePackage) && !s.equals(this.getPackageName())) {
                    Intent dialogIntent = new Intent(this, LockAct.class);
                    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    dialogIntent.putExtra("lock", s);
                    startActivity(dialogIntent);
                    kes = s;

                }
            }
        }

    }
4

0 回答 0