2012-01-24 2 views
0

배경에서 다양한 웹 서비스를 초기화하는 동안 응용 프로그램 시작 화면을 5 초 동안 표시하려고합니다. 내가 일한다고 생각하면 시작 화면이 표시되는 동안, 응용 프로그램 로그를해야한다는 것입니다 이제백그라운드 작업이있는 스플래시 화면

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    // Splash screen view 
    setContentView(R.layout.splashscreen); 

    final SplashScreen sPlashScreen = this; 

    // The thread to wait for splash screen events 
    mSplashThread = new Thread() 
    { 
     @Override 
     public void run() 
     { 
      try { 
       synchronized(this){ 
        // Wait given period of time or exit on touch 
        wait(5000); 
       } 
      } 
      catch(InterruptedException ex) 
      {      
      } 
      finally 
      { 

       finish(); 


       // Run next activity 
       Intent intent = new Intent(); 
       intent.setClass(sPlashScreen, Splash_testActivity.class); 
       startActivity(intent); 
       stop(); 
      } 
     } 
    }; 

    mSplashThread.start(); 

    for (int i=0;i<100;i++) 
    Log.d("splash test", "initialize web methods"); 
} 

: 여기 내 코드입니다 "웹 방법을 초기화합니다."

하지만 실제로는 슬래시 화면이 사라진 후에 만 ​​로그가 추가됩니다.

내가 뭘 잘못하고 있니?

답변

1

시도해보십시오. this way. 이 자습서는 간단하고 유연합니다. 필요한 항목 :

// You initialize _splashTime to any value 

// thread for displaying the SplashScreen 
Thread splashTread = new Thread() { 
    @Override 
    public void run() { 
     try { 
      int waited = 0; 
      while(waited < _splashTime)) { 
       sleep(100); 
       waited += 100; 
      } 
      } 
     } catch(InterruptedException e) { 
      // do nothing 
     } finally { 
      finish(); 
      startActivity(new Intent("com.droidnova.android.splashscreen.MyApp")); 
      stop(); 
     } 
    } 
}; 
splashTread.start(); 

참고 :이 코드는 위의 URL에서 채택되었습니다.

+0

잠깐만 기다려주세요. sleep() 문제를 해결했습니다. 이유는 확실하지 않지만. 어떤 아이디어 ??? –

+0

@ user1166495 기꺼이 도와 드리겠습니다. 이 두 가지 방법의 차이점은 여전히 ​​분명하지 않습니다. 나는 [이 위대한 대답] (http://stackoverflow.com/a/1036763/543711)을 발견했다. 그러나 나는 그것으로부터 명확한 그림을 아직 얻지 못했다! – iTurki

0

처리기 또는 AsyncTask를 사용하여 스레드를 실행하십시오.