gpt4 book ai didi

android - 小部件提供者的生命周期

转载 作者:行者123 更新时间:2023-11-29 21:46:23 25 4
gpt4 key购买 nike

我很难找到这方面的文档。对于 android 小部件的提供者,该特定提供者对象的生命周期是什么?我注意到如果我开始异步测试然后在稍后查找该对象,它就会消失。(通过观察,我可以从 onReceive 调用 onUpdate,并且我可以知道在 onUpdate 完成之前接收到的将一直存在)

最佳答案

AppWidgetProvider 是一个BroadcatReceiver。您可以在 BroadcatReceive 和 AppWidgetProvider 中找到有用的信息。 Google Docs说:

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.

另请参阅 this web page .

关于android - 小部件提供者的生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15697365/

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