android - Show alertdialog from service -
i need show alertdialog service , i'm using code on service:
public void oncreate() { intent i=new intent(getapplicationcontext(), groupactivity.class); alertdialog.builder alert=new builder(getapplicationcontext()); alert.settitle("success!"); alert.setmessage("hien tai"); alert.setpositivebutton("success", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { } }); alert.show(); };
but code throw execption. how that?
public void oncreate() { intent i=new intent(getapplicationcontext(), groupactivity.class); alertdialog alertdialog = new alertdialog.builder(this) .settitle("success!") .setmessage("hien tai") .setpositivebutton("success", new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { } }).create(); alertdialog.getwindow().settype(windowmanager.layoutparams.type_system_alert); alertdialog.show(); }
please note have use following permission:
<uses-permission android:name="android.permission.system_alert_window" />
Comments
Post a Comment