【问题标题】:Implement Thread in my class? [duplicate]在我的课堂上实现线程? [复制]
【发布时间】:2013-09-27 18:48:41
【问题描述】:

我想知道如何在这个类中实现一个线程以使其免受 ANR(应用程序无响应)问题的影响

public class myClass {


    private static String LOG_TAG = Root.class.getName();

    public boolean isDeviceRooted() throws IOException {

        if (checkRootMethod1()){return true;}
        if (checkRootMethod2()){return true;}
        if (checkRootMethod3()){return true;}
        return false;

    }
    public boolean checkRootMethod1(){
        String buildTags = android.os.Build.TAGS;

        if (buildTags != null && buildTags.contains("test-keys")) {
            return true;
        }
        return false;
    }

    public boolean checkRootMethod2(){
        try {
            File file = new File("/system/app/Superuser.apk");
            if (file.exists()) {
                return true;
            }
            else {

                return false;
            }
        } catch (Exception e) {

        }

        return false;
    }

    public boolean checkRootMethod3() {
        if (new ExecShell().executeCommand(SHELL_CMD.check_su_binary) != null){
            return true;
        }else{
            return false;
        }
    }


            }

例如,如果在我按下按钮时执行此代码,如果我多次按下此按钮,我的应用程序就会出现 ANR。

【问题讨论】:

  • 认真的吗?你问一个问题,然后在 10 分钟内重复一遍?那一定是记录!
  • 对不起,我的网络连接有问题。

标签: java android xml root


【解决方案1】:

你应该做这样的事情:

new Thread(new Runnable(){ 
  @Override
  public void run(){
   boolean isRooted = isDeviceRooted();
   rootedListener.isDeviceRooted(isRooted);
  }
}

然后声明一个监听器来获取异步响应

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多