Activity中显示dialog:
Dialog dialog = new Dialog(Service.this);
dialog.setTitle("Network error!");
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
dialog.show();
在service中按照上面的方式会提示:
AndroidRuntime: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
解决此问题需要做如下修改:
Looper.prepare();
Dialog dialog = new Dialog(Service.this);
dialog.setTitle("Network error!");
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
dialog.show();
Looper.loop();
做个记录。