当前位置: 代码迷 >> Android >> Android:在Service中应用Toast
  详细解决方案

Android:在Service中应用Toast

热度:12   发布时间:2016-05-01 13:56:33.0
Android:在Service中使用Toast
在Service中Toast,本来以为是和在Activity中一样直接用,结果发现没有反应,百度到的解决办法,原理暂时不清楚。
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();               }          });    }}		
  相关解决方案