广播接收器问题需要帮助吗?

发布于 2024-12-02 06:20:07 字数 303 浏览 2 评论 0原文

我创建了一个广播接收器。之后在onReceive中,收到一条信息,调用了类中的一个方法。

我的问题是,当我调用该方法时,我只想调用一次,但为什么它调用多次?

有什么方法可以确定 onReceive 只收到一个???

编辑

我在onReceiver中调用的方法是更新类扩展MapActivity中的地图位置

我还在manisfest.xml中注册了我的广播服务

我想在答案中添加注释,但我不能不知道为什么

我们如何确定我们的广播接收器只接收一个? 谢谢

I created a broadcast receiver. After that in onReceive, I received an information and called a method in the class.

my question is when I call that method I want to call only once but why it calls more than one time?

Are there any way we can determine that onReceive receive only one ???

EDIT

my method that I call in onReceiver is update map location in class extend MapActivity

I also register my broadcast service in manisfest.xml

I want to add comment to the answer but i can't i don't know why

how can we determine to our broadcast receiver to receiver only one??
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ双果 2024-12-09 06:20:07

您可以维护一个 bool 变量,当您在方法中第一次调用时,将其设为 bool true ,下次在调用您的方法之前可以使用这个 bool 变量进行检查。

如果您没有在清单文件中注册接收器,那么您可以在注册接收器之前使用此布尔值。

you can maintain a bool variable and when you get call first time in the method, make this bool true and next time before calling the method you can put check there using this bool variable.

If you are not registering your receiver in the manifest file then you can use this bool value before registering the receiver.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文