<span style="background-color: rgb(255, 255, 255); font-family: Arial, Helvetica, sans-serif;">MainActivity启动Display,由Display传回信息</span>
MainActivity调用sendMessage,启动Display:
public void sendMessage(View view)
{
EditText messageSend = (EditText)this.findViewById(R.id.input_info);
String message = messageSend.getText().toString();
System.out.println(message+"***********");
Intent messageIntent = new Intent(this,Display.class);
messageIntent.putExtra(SEND_MESSAGE, message);
startActivityForResult(messageIntent, 1);
}
Display调用MessageBack结束Display
public void MessageBack(View view)
{
Intent intent = new Intent();
intent.putExtra(IS_SUCCESS, "发送成功");
setResult(RESULT, intent);
finish();
}
MainActivity调用 onActivityResult获得返回值
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
// TODO Auto-generated method stub
<span style="white-space:pre"> </span>super.onActivityResult(arg0, arg1, arg2);
EditText backMessage = (EditText)this.findViewById(R.id.back_message);
switch (arg1) {
case 0:
backMessage.setText("发送失败!!!!");
break;
default:
backMessage.setText(arg2.getStringExtra(Display.IS_SUCCESS));
break;
}
}