如何在service中显示Dialog
2017-08-17 16:47
302 查看
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();
做个记录。
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();
做个记录。
相关文章推荐
- 如何在service中显示对话框dialog
- 如何设置dialog显示的位置
- Service如何弹出dialog
- Android在Service中显示Dialog
- Android如何将Activity以Dialog的形式显示
- Android的startForeground前台Service如何去掉通知显示
- 如何在service中弹出dialog
- 如何在服务(Service)程序中显示对话框
- service 中显示AlertDialog
- 如何在服务(Service)程序中显示对话框
- MFC 如何给Dialog 显示Menu菜单。
- 如何在service中弹出dialog
- service中显示一个dialog
- 如何在service中弹出dialog
- 如何在service中弹出dialog
- android 如何显示模态的 DialogFragment。
- Android如何将Activity以Dialog的形式显示
- How to show a modal dialog and modeless dialog using C++ - 如何用C++显示一个模态对话框和一个非模态对话框
- 如何在服务(Service)程序中显示对话框
- service如何弹出dialog