public static void showErrorDialog(Context context) { Builder builder = new AlertDialog.Builder(context); builder.setMessage("程序发生异常,即将退出"); builder.setIcon(R.drawable.image_dialog); builder.setNegativeButton("确定", null); builder.setPositiveButton("取消", null); AlertDialog alertDialog = builder.create(); alertDialog.getWindow().setType( WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); alertDialog.show(); }context 对象可以是Service,Application
<!-- 全局dialog权限 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
?