How do I display dialog from a service?
From a Service, you can easily show a Material Design styled Dialog manipulating its Window type, attributes and LayoutParams.
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.
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.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With