广播接收器问题需要帮助吗?
我创建了一个广播接收器。之后在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以维护一个
bool
变量,当您在方法中第一次调用时,将其设为bool
true
,下次在调用您的方法之前可以使用这个bool
变量进行检查。如果您没有在清单文件中注册接收器,那么您可以在注册接收器之前使用此布尔值。
you can maintain a
bool
variable and when you get call first time in the method, make thisbool
true
and next time before calling the method you can put check there using thisbool
variable.If you are not registering your receiver in the manifest file then you can use this bool value before registering the receiver.