Android:在Service中应用Toast

Android:在Service中使用Toast在Service中Toast,本来以为是和在Activity中一样直接用,结果发现没有反应,百

Android:在Service中使用Toast
在Service中Toast,本来以为是和在Activity中一样直接用,结果发现没有反应,百度到的解决办法,原理暂时不清楚。

public class TestService extends  Service {private Handler handler;@Overridepublic IBinder onBind(Intent intent){return null;}@Overridepublic 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();               }          });    }}