2012-09-26 71 views
0

我想等待啓動畫面完成他的任務,然後繼續執行該活動。 我認爲我的錯誤是因爲太多的時間來等待啓動畫面,我的啓動畫面是從服務器獲取一些字符串,它具有所有需要的。 ,創造,需要等待完成閃屏第一類是: 更新:如何等待啓動畫面將完成

  Thread splashTread = new Thread() { 
       @Override 
       public void run() { 
        try { 
         splash splash=(tools.splash) new splash(first.this).execute(); 
         int waited = 0; 
         while(splash.running && (waited< getResources().getInteger(R.integer.splashTimeOut))) 
         { 
          sleep(100); 
          if(splash.running) { 
           waited += 100; 
          } 
          // nextActivity=splash.newActivity; 
         } 
        } catch(InterruptedException e) { 
         // do nothing 
        } finally { 
         finish(); 

        } 
       } 
      }; 
      splashTread.start(); 

而閃屏是確定其

public class splash extends AsyncTask<String, Void, String> 

其錯誤的,因爲它創建一個新的活動,然後做線....

回答

0

我希望我的代碼將有助於你

public void onStart() 
    { 
     super.onStart(); 

     Thread background = new Thread(new Runnable() 
     { 
      public void run() 
      { 
       try 
       { 
        Thread.sleep(3000); 
        Intent langSelect = new Intent(EduApp.this, LanguageActivity.class); 
        startActivity(langSelect); 
        genHelper.goForwardScreen(); 
       } 
       catch (Throwable t) 
       {    
        System.err.println("Thread Exception IN Splash Screen->" + t.toString()); 
       } 
      } 
     }); 
     background.start(); 
    } 

開始下一個活動在這裏..

2
public void onCreate(Bundle savedInstanceState) { 
    protected boolean _active = true; 
    protected int _splashTime = 1000; 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    Thread splashTread = new Thread() { 
     @Override 
     public void run() { 
      try { 
       int waited = 0; 
       while(_active && (waited < _splashTime)) { 
        sleep(100); 
        if(_active) { 
         waited += 100; 
        } 
       } 
      } catch(InterruptedException e) { 
       // do nothing 
      } finally { 
       finish(); 

      } 
     } 
    }; 
    splashTread.start(); 
+0

我更新在主後我的代碼,但還是顯得它做下一個活動,而不是等待線程(閃屏) –