Android 进程间服务通信
2010-04-12 03:39:00 来源:WEB开发网public String getCurrentDataTime() {
return (getCurrentDataTimeImpl());
}
};
synchronized private String getCurrentDataTimeImpl() {
Date date=new Date();
return (date.toLocaleString());
}
@Override
public IBinder onBind(Intent intent) {
return (binder);
}
}
Java代码
public class DataTimeService extends Service{
public static final String BROADCAST_ACTION = "com.services.demo2.DataTimeServiceEvent";
/**
使用上面定义的字符串常量创建一个Intent的实例,如果服务在运行的过程中发生的事件都可以通过Service的
sendBroadcast(broadcast)方法来发送一个广播消息通知Activity,然后有Activity注册的接收者进行处理;
*/
private Intent broadcast = new Intent(BROADCAST_ACTION);
sendBroadcast(broadcast);
private final IDataTimeService.Stub binder = new IDataTimeService.Stub() {
public String getCurrentDataTime() {
return (getCurrentDataTimeImpl());
}
};
synchronized private String getCurrentDataTimeImpl() {
Date date=new Date();
return (date.toLocaleString());
}
@Override
public IBinder onBind(Intent intent) {
return (binder);
}
}
public class DataTimeService extends Service{
public static final String BROADCAST_ACTION = "com.services.demo2.DataTimeServiceEvent";
/**
使用上面定义的字符串常量创建一个Intent的实例,如果服务在运行的过程中发生的事件都可以通过Service的
sendBroadcast(broadcast)方法来发送一个广播消息通知Activity,然后有Activity注册的接收者进行处理;
*/
private Intent broadcast = new Intent(BROADCAST_ACTION);
sendBroadcast(broadcast);
private final IDataTimeService.Stub binder = new IDataTimeService.Stub()
更多精彩
赞助商链接