Android 进程间服务通信
2010-04-12 03:39:00 来源:WEB开发网DataTimeService中的调用sendBroadcast(broadcast)发送的广播消息;
*/
registerReceiver(receiver, new IntentFilter(
DataTimeServiceImpl.BROADCAST_ACTION));
}
@Override
public void onPause() {
super.onPause();
unregisterReceiver(receiver);
}
@Override
public void onDestroy() {
super.onDestroy();
unbindService(svcConn);
}
private void updateForecast() {
try {
String page = service.getForecastPage();
if (page != null) {
browser.loadDataWithBaseURL(null, page, "text/html", "UTF-8",
null);
browser.postDelayed(new Runnable() {
public void run() {
updateForecast();
}
}, 1000);
}
} catch (final Throwable t) {
svcConn.onServiceDisconnected(null);
}
}
//接收者实例
private BroadcastReceiver receiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
runOnUiThread(new Runnable() {
public void run() {
updateForecast();
}
});
}
};
}
更多精彩
赞助商链接