Is it possible to show pop up dialog (AlertDialog) in home screen on the android device via services?
4 Answers
You could create an Activity
with the Theme.Dialog
theme. In your AndroidManifest.xml
file add the theme to the activity, like this:
<activity android:name=".DialogActivity" android:theme="@android:style/Theme.Dialog"></activity>
From your service simply start this Activity
. You will have to start the activity with the Intent.FLAG_ACTIVITY_NEW_TASK
flag. See How to start an Activity from a Service

- 1
- 1

- 7,442
- 9
- 46
- 69
-
Aki,Dallas: I have used this Theme.Dialog and works successfully. Thanks for that but i have one question what to do to remove this dialog box on button click??? – Kushal Shah Mar 19 '12 at 10:53
-
Call finish() in the onclicklistner of the button – Arnab Chakraborty Mar 20 '12 at 05:02
Does anyone needs option, "android:launchMode="singleInstance", when pop activity in the broadcast receiver or Service?? Without this option, my app started automatically and pop MyDialogActivity above it. And then, something happened wrong. (My app has the Main Activity with auto-login function. When the other new Activity started automatically, MyDialogActivity is hided by it.)
So, this is my sample xml code.
<activity
android:name=".MyDialogActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Dialog" />
<activity
I hope someone needs my comments. :)

- 2,289
- 1
- 25
- 26
-
1have been stumbling on the internet for hours, setting the launchMode helps, thx. – Dino Tw Oct 23 '15 at 18:42
You can not create dialog from service but we have one alternative solution is that You can create dialog activity
and start that activity from your service
You can set Theme of activity as dialog by below way
<activity android:name=".MyDialogActivity" android:theme="@android:style/Theme.Dialog"
android:label="@string/app_name">
</activity>

- 33,296
- 22
- 86
- 129
Create CustomDialog As Activity
add to manifest
<activity android:name=".view.activity.CustomDialog"
android:launchMode="singleInstance"
android:screenOrientation="fullSensor"
android:theme="@style/AlertDialogTheme"
/>
add Style AlertDialogTheme to style.xml
<style name="AlertDialogTheme" parent="Theme.MaterialComponents.Light.Dialog.Alert.Bridge">
</style>

- 495
- 1
- 5
- 13