弹出对话框中的Andr​​oid主屏幕弹出、屏幕、对话框中、Andr

2023-09-05 08:52:02 作者:踏雪寻

是否有可能通过服务显示在主屏幕上弹出对话框(AlertDialog)在Android设备上?

解决方案

您可以创建一个活动 Theme.Dialog 主题。在你的的Andr​​oidManifest.xml 文件中添加主题活动,像这样的:

 <活动机器人:名称=机器人:主题=DialogActivity。@安卓风格/ Theme.Dialog>< /活性GT;
 

这是您的服务只需启动该活动。你将不得不开始活动与 Intent.FLAG_ACTIVITY_NEW_TASK 标志。请参见如何从服务

Is it possible to show pop up dialog (AlertDialog) in home screen on the android device via services?

解决方案

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