广播中读写变量冲突问题

learning8899 2014-08-27 02:53:02
类中,i为私有变量。
一个while函数,判断i, 赋值i++
广播中,判断i,赋值i++
请教一下,会不会引起冲突?
...全文
142 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
learning8899 2014-08-27
  • 打赏
  • 举报
回复
谢谢,我研究一下看。 目前广播也在线程类中注册的。
coxfilur_2008 2014-08-27
  • 打赏
  • 举报
回复
You can avoid the collision. Visit on both on the main thread. You can make sure your BroadcastReceiver.onReceive called in main thread(there is related API to set this, and it is default behavior to be called on main thread).
learning8899 2014-08-27
  • 打赏
  • 举报
回复
很头疼模拟不出这个问题。冲突会不会让程序崩溃?还是仅仅读上次的数?
lionfresh 2014-08-27
  • 打赏
  • 举报
回复
有可能发生冲突。

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧