2013-09-27 77 views
-2

我想知道如何实现一个线程在这个类,使其从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。

+0

真的吗?你问一个问题,然后在10分钟内重复一遍?那一定是个记录! – Simon

+0

对不起,我的网络连接出现问题。 –

回答

0

你应该是这样的:

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

然后声明一个监听器,以获得异步响应