2012-02-25 3 views
4

로그가 "안녕하세요"한 번만 표시하고, 토스트Android - ScheduledExecutorService를 사용하여 10 초마다 토스트를 실행하는 방법?

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    ScheduledExecutorService scheduler = 
      Executors.newSingleThreadScheduledExecutor(); 
    scheduler.scheduleAtFixedRate(new Runnable() { 

     public void run() { 
      Log.i("hello", "world"); 
      Toast.makeText(getApplicationContext(), "It works", Toast.LENGTH_SHORT).show(); 
      // TODO Auto-generated method stub 

     } 
    }, 10, 10, TimeUnit.SECONDS); 

} 

답변

8

 scheduler.scheduleAtFixedRate(new Runnable() { 

     public void run() { 
      Log.i("hello", "world"); 
      runOnUiThread(new Runnable() { 
       public void run() { 
        Toast.makeText(getApplicationContext(), "It works", Toast.LENGTH_SHORT).show(); 
       } 
      }); 

     } 
    }, 10, 10, TimeUnit.SECONDS); 
+1

Thnx 브로 시도 .. 전혀 나타나지 않았다, 그것은 :) 작품 – SaberTrika