Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert dialog from Android service

How do I display dialog from a service?

like image 292
d-man Avatar asked Aug 30 '10 10:08

d-man


People also ask

Can I show dialog from service android?

From a Service, you can easily show a Material Design styled Dialog manipulating its Window type, attributes and LayoutParams.

What is alert dialog in Android?

Alert Dialog shows the Alert message and gives the answer in the form of yes or no. Alert Dialog displays the message to warn you and then according to your response the next step is processed. Android Alert Dialog is built with the use of three fields: Title, Message area, Action Button.

Can we show dialog from service?

You cannot show a dialog. But you can go the alernative way by inflating your customized view so that you can show a dialog on the screen whenver certain conditions are met.


1 Answers

Another way without using an activity:

AlertDialog alertDialog = new AlertDialog.Builder(this)                     .setTitle("Title")                     .setMessage("Are you sure?")                     .create();  alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); alertDialog.show(); 

Please note that you have to use this permission:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> 
like image 157
Eliran Kuta Avatar answered Sep 25 '22 05:09

Eliran Kuta