1.点击button 发送Handler1 Message 收到消息 开启线程进行处理

2.收到消息 后调用已经绑定的 mService mService.sendMail()方法

mService.sendMailAlarm(SEND_MAIL_TYPE,subject,body.toString()); --Activity类

Service类

private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {

public void sendMail(int type, String subjectText, String sendText)
throws RemoteException {
Constant.Log("sendMailAlarm", "RunKKKKKK");
new SendMailAlarmMsgThread(type, subjectText, sendText).start();
}



3 。SendMailAlarmMsgThread 处理完发送 Service Handler2 消息

4. 处理接受到的信息后 回调函数调用

Service类

private final RemoteCallbackList<IRemoteServiceCallback> mCallbacks = new RemoteCallbackList<IRemoteServiceCallback>();

private void _makeSendMailResultCallbacksWork(int result) {
Constant.Log("RemoteService", "_makeSendMailResultCallbacksWork");
// Broadcast to all clients the new value.
Constant.Log("onSendMailReturn", "RunKKKKKK");
try {
final int N = mCallbacks.beginBroadcast();
for (int i = 0; i < N; i++) {
try {
mCallbacks.getBroadcastItem(i).onSendMailReturn (result);
} catch (RemoteException e) {
Constant.exception(e);
}
}
mCallbacks.finishBroadcast();
} catch (Exception e) {
e.printStackTrace();
}
}

onSendMailReturn

在Activity 类中实现

  private IRemoteServiceCallback mCallback = new IRemoteServiceCallback.Stub() {             @Override        public void onSetPowerStatusReturn(String arg0, String arg1) throws RemoteException {            // TODO Auto-generated method stub        }        @Override        public void onSendMailReturn(int arg0) throws RemoteException {            // TODO Auto-generated method stub            LogOut("call method : onSendMailReturn()---" + arg0);            // if (!isClickMailBtn) return ;            // isClickMailBtn = false ;            switch (arg0) {                case 0:                    mHandler.removeMessages(MAIL_RECEIVE_SUCCESS_RESULT_ORDER);                    mHandler.sendEmptyMessage(MAIL_RECEIVE_SUCCESS_RESULT_ORDER);                    break;                case 1:                    mHandler.removeMessages(MAIL_RECEIVE_FAILURE_RESULT_ORDER);                    mHandler.sendEmptyMessage(MAIL_RECEIVE_FAILURE_RESULT_ORDER);                    break;                default:                    break;            }        }    };

处理完后发送Handler1 消息 更新画面

耗时操作UI更行超过5秒!

Service 参考http://hi.baidu.com/xtlp/blog/item/e6e18810ad6c030c213f2eaf.html

本地服务和远程服务

Android 监听事件 一旦监听一直会有守护线程监听。

更多相关文章

  1. Android常用Dialog总结
  2. Android注解——Butter Knife的使用
  3. 《Android应用开发揭秘》读者问题汇总
  4. Android之Broadcast, BroadcastReceiver(广播)
  5. 安卓中使用ThreadPoolExcutor
  6. Android(安卓)Service两种启动方式
  7. Android面试题目(10) 内存泄露
  8. Android(安卓)认识EventBus到原理解析
  9. Android(安卓)JVM的运行过程

随机推荐

  1. Spring小记
  2. [SpringCloud教程]4. Zookeeper服务注册
  3. 【spring源码系列】之【环境搭建】
  4. Spring 获取 request 的几种方法及其线程
  5. SpringCloudAlibaba—微服务概念及Spring
  6. 手把手教你写一个spring IOC容器
  7. Spring Boot之发送HTTP请求(RestTemplate
  8. 别再面向 for 循环编程了,Spring 自带的观
  9. Spring 天天用,bean 懒加载原理你懂吗?
  10. Pytorch