## 2.3.5 Robot的處理流程
* MainService的
~~~
public int onStartCommand(Intent intent, int flags, int startId)
~~~
* 接收到SEND_MSG或者SEND_VOICE_MSG后,提取Intent中的文本,或者從語音識別結果
onRecognizeResult(String)中獲得輸入文本,然后調用:
~~~
public void sendMessageToRobot(String text, int type)
~~~
* 方法處理文本輸入,靈聚智能引擎(robot)處理完畢后,會回調
~~~
/**
* 靈聚智能引擎應答輸出回調
* @param text 輸出文本
* @param type 輸入類型,0=文本輸入,1=語音輸入
*/
protected void onRobotResponse(String text,Command cmd,int type){…}
~~~
* 該方法會將robot返回的指令返回至方法中,開發者需在這些回調方法中解析并執行應答指令,指令說明詳見3.6節(或者api的Command類說明),指令解析并執行完成后可通過EventBuspost到前端Activity,在Activity中可以這樣接收:
~~~
public void onEventMainThread(RobotResponseEvent e){
if(TextUtils.isEmpty(e.getText()))return;
history.add(new Msg(e.getText(), Msg.OUTPUT_TYPE));
adater.notifyDataSetChanged();
recyclerView.scrollToPosition(history.size() - 1);
}
~~~
詳見Demo中的MainCommonActivity;