WEB开发网
开发学院手机开发Android 开发 Android 进程间服务通信 阅读

Android 进程间服务通信

 2010-04-12 03:39:00 来源:WEB开发网   
核心提示:{public String getCurrentDataTime() {return (getCurrentDataTimeImpl());}};synchronized private String getCurrentDataTimeImpl() {Date date=new Date();return (dat
{

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()

上一页  1 2 3 4  下一页

Tags:Android 进程 服务

编辑录入:coldstar [复制链接] [打 印]
赞助商链接