首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android 兑现service动态更新UI界面

2012-08-30 
android 实现service动态更新UI界面根据android API的介绍,service一般是在后台运行的,没有界面的。那么如

android 实现service动态更新UI界面
根据android API的介绍,service一般是在后台运行的,没有界面的。那么如何实现service动态更新UI界面呢?
 案例:通过service向远程服务器发送请求,根据服务器返回的结果动态更新主程序UI界面,主程序可实时关闭或重启服务。所属项目:《一呼百应客户端》
 方法:[list]在主程序activity中注册一个BroadcastReceiver,用于接收Service发布的广播。 

/** * 启动一个子纯种并连接服务器,接收服务器返回数据data。代码略。。。 */Object data;//服务器返回的数据dataIntent intent = new Intent();//创建Intent对象intent.setAction("com.justel.service");intent.putExtra("data", data);sendBroadcast(intent);//发送广播

好了,主程序就可以通过接收广播实时更新UI了。就写到这里,太忙了,没时间细讲。

热点排行