2012-09-26 39 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

我更新在主后我的代码,但还是显得它做下一个活动,而不是等待线程(闪屏) –