bindService后,onServiceConnected方法没有执行
来源:互联网 发布:网络十二主神 编辑:程序博客网 时间:2024/06/07 19:28
在体验bindService功能时候,执行过bindService后,也返回绑定成功,但是发现获取Service的对象mBoundService一直为空,onServiceConnected没有执行,一个晚上没想明白,也尝试了网上的一些做法,直到看到了下面的方法(http://www.itwendao.com/article/detail/286559.html),搞定。
即下面mBoundService引用的代码从onCreate挪到onServiceConnected里去
mBoundService = (mMusicBinder).getService(); mBoundService.addMusicStateChangedListener(MainActivity.this); mBoundService.setPath(DatabaseModel.getDatabaseModelInstance(MainActivity.this) .getMusicItemById(1).getPath()); mBoundService.setPlayingId(1);
官网对于bindService有句描述:
Connect to an application service, creating it if needed. This defines a dependency between your application and the service. The given conn will receive the service object when it is created and be told if it dies and restarts. The service will be considered required by the system only for as long as the calling context exists. For example, if this Context is an Activity that is stopped, the service will not be required to continue running until the Activity is resumed.
大意是,onServiceConnected在绑定成功时进行回调,但不保证在执行bindService后立马回调,我们在onCreate方法中绑定后立马获取service实例,但此时不保证onServiceConnected已经被回调。 也就是我们onCreate方法执行时onServiceConnected还没有别调用。此时当然mBoundService还为空了。
- bindService后,onServiceConnected方法没有执行
- bindService不能触发onServiceConnected方法
- android service bindService onServiceConnected没有调用
- bindService不能触发onServiceConnected方法的原因
- bindService不能触发onServiceConnected方法的原因
- Android AIDL bindService后不能调用onServiceConnected方法(一种情况)
- android: unbindService 后,第二次 bindService 执行后没有作用?
- Android Service在bindService不能触发onServiceConnected方法
- Android Service在bindService不能触发onServiceConnected方法
- 调用了bindService()之后,程序执行了Service里的onBind(),但是为什么不执行ServiceConnection对象接口onServiceConnected()呢?
- bindService不调用onServiceConnected的问题
- ServiceConnection中onServiceConnected不执行
- Service的onServiceConnected没有被调用
- Service的onServiceConnected没有被调用
- Service的onServiceConnected没有被调用
- mybatis dao层执行sql时,方法执行后没有任何反应
- 不回调ServiceConnection中onServiceConnected()方法的问题
- 为什么代理方法没有执行?
- linux 查看系统信息的一些命令及查看已安装软件包的命令
- HashMap、LinkedHashMap元素遍历机制探讨
- ffmpeg 编码 apng 解决内存泄露问题
- Ubuntu16成功安装QQ2012国际版(wine1.6.2)
- 深入理解计算机1.2 --HolleWord的程序运行到底经历了什么?
- bindService后,onServiceConnected方法没有执行
- Netty API 中文翻译(4.1.11.Final) —— 缘由
- 时间控件:my97DatePicker选择年、季度、月、周、日
- ROS教程1--创建节点
- PI与RFC连接测验
- mybatis打印出sql语句
- C#网络编程(三、Socket同步传输字符串)
- 截断文件函数truncate和ftruncate
- 基于局部标准差的的局部对比度增强算法