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

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

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

  1. while (true) {
  2. String s = getlauncherTopActivity();
  3. if (utils.islock(s)) {
  4. if (!s.equals(kes)) {
  5. if (!s.equals(currentHomePackage) && !s.equals(this.getPackageName())) {
  6. Intent dialogIntent = new Intent(this, LockAct.class);
  7. dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  8. dialogIntent.putExtra("lock", s);
  9. startActivity(dialogIntent);
  10. kes = s;
  11. }
  12. }
  13. }
  14. }

暂无答案!

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

相关问题