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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -