2013-10-24 68 views
0

也许样的代码显示了什么,我试图做的,所以我也有许可证检查循环?

private void getLicenseResults() { 

    if (licensed && didCheck == true) { 

     Thread timer = new Thread() { 
      public void run() { 
       try { 
        sleep(2000); 
       } catch (InterruptedException e) { 
        e.printStackTrace(); 
       } finally { 
        Intent openStartingPoint = new Intent(
          "***.MAINACTIVITY"); 
        startActivity(openStartingPoint); 
        finish(); 
       } 
      } 
     }; 
     timer.start(); 
    } 

    if (didCheck == false) { 

     Toast.makeText(Splash.this, "Checking License, Please Wait", 
       Toast.LENGTH_LONG).show(); 

     Thread timer = new Thread() { 
      public void run() { 
       try { 
        sleep(2000); 
       } catch (InterruptedException e) { 
        e.printStackTrace(); 
       } finally { 
        getLicenseResults(); 
        Log.i("LICENSE", "re-checking"); 
       } 
      } 
     }; 
     timer.start(); 
    } 

} 

我跑许可检查没有它之前尝试循环开始,它的工作,除非检查了超过几秒钟就跳过了

if (licensed && didCheck == true) 

和活动只是一种站着,等待,而无需启动我的主要活动(此检查是在启动屏幕上)。

所以我希望只有在didCheck事实上最终真实之后才能调用“if didCheck = true”部分。我确信有一个简单的解决方案,但我是自学成才的,我没有使用循环或回调(?)的经验。

谢谢你的帮助!

回答

0

你是不是在你的第二个设定didCheck为true,如果调用getLicenseResults

+0

didCheck是在这个后台进程目前正对设置为true之前声明。 “许可证检查器”是一个单独的类,当它最终完成时(速度因互联网连接而异),它将didCheck从false设置为true。 – RyWalk