java—有没有更好的方法来检查顶级活动是否发生了变化?

cwxwcias  于 2021-07-11  发布在  Java
关注(0)|答案(0)|浏览(236)

我在一个applocker应用程序上工作,我使用下面的函数来检查top活动的变化,但是有没有比使用“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;

                }
            }
        }

    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题