gpt4 book ai didi

android - 从 AppWidget 打开 PopUpWindow

转载 作者:行者123 更新时间:2023-11-29 02:07:52 24 4
gpt4 key购买 nike

由于似乎无法将 EditText 放入 AppWidget,因此我想在单击它时打开带有 EditText 的 PopUpWindow。

我知道如何从 AppWidget 打开 Activity,我也知道如何从 Activity 打开 PopUpWindow。但是,我不知道如何从 AppWidget 打开 PopUpWindow。我查看了 javadoc 中的许多类(Intent、RemoteViews、PendingIntent 等),但找不到如何启动此 PopUpWindow。任何帮助将不胜感激。

最佳答案

您知道 AppWidgetProvider 是一个 BroadcastReceiverAndroid Doc说:

A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.

This has important repercussions to what you can do in an onReceive(Context, Intent) implementation: anything that requires asynchronous operation is not available, because you will need to return from the function to handle the asynchronous operation, but at that point the BroadcastReceiver is no longer active and thus the system is free to kill its process before the asynchronous operation completes.

In particular, you may not show a dialog or bind to a service from within a BroadcastReceiver. For the former, you should instead use the NotificationManager API. For the latter, you can use Context.startService() to send a command to the service.

看来你有三种方法:

  1. 使用服务显示弹出窗口(参见 How to display alert diaolog(popup) from backgroung running service? )
  2. 使用通知管理器(参见 AlarmManager never calling onRecieve in AlarmReceiver/BroadcastReceiver)。
  3. 创建一个带有对话框主题的 Activity (因此它看起来像一个弹出窗口)并在用户单击您的 AppWidget 时显示它。

关于android - 从 AppWidget 打开 PopUpWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8991214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com