Service中调用Toast小记

Toast 显示需要出现在一个线程的消息队列中

public class TestService extends    Service { 
  private Handler handler; 
  @Override 
  public IBinder onBind(Intent intent){ 
    return null
  } 
    
  @Override 
  public void onCreate(){ 
         handler = new Handler(Looper.getMainLooper());                                                 
                System.out.println("service started"); 
         handler.post(new Runnable() {     
                         @Override     
                         public void run() {     
                                Toast.makeText(getApplicationContext(), "Test",Toast.LENGTH_SHORT).show();     
                         }     
                }); 
        } 
}     

猜你喜欢

转载自blog.csdn.net/sinat_31841263/article/details/53257839
今日推荐